DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Zero Trust, Build High Scale TLS Termination Layer
  • Close Site Search Indexing via Kubernetes HAProxy Ingress
  • Optimizing Server Management With HAProxy’s Advanced Health Checks
  • Implementing HTTP Load Balancer Using HAProxy on AWS

Trending

  • Beyond the Endpoint: How Agent Cards Enable Discovery, Interoperability, and Trust
  • Google Cloud KMS vs. AWS KMS: Java Encryption Guide
  • The Self-Hosting Math Changed While We Were Still Arguing About Sovereignty
  • GenAI Security Gateway: An End-to-End Architecture

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. HAProxy Performance Tweaks: sysctl and config

HAProxy Performance Tweaks: sysctl and config

Learn about the changes you should make to sysctl and HAProxy configurations to improve the performance of your entire setup.

By 
Nadine Arnold
·
May. 07, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
18.6K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

If you’re running a high-performance HAProxy setup, there are many tweaks and settings that you can benefit from. Some of these can be complex, but there are many that can quite easily increase your performance. We’ll give you some tips here to get that extra bit of performance you need!

Warning: These are mostly kernel changes and can cause unknown issues. Please Google any changes you are unsure of, or ask us!

Sysctl.conf Changes

sysctl is a program used to tweak kernel settings on your OS. These can allow you to optimize specifically the way your kernel is handling things — specifically, networking. If you are using Snapt, for HAProxy you can navigate to the Setup > Configuration > Performance menu. Alternatively, you can manually edit the /etc/sysctl.conf file.

These are specifically designed to optimize your Linux installation forhaproxy, allowing it to perform better under peak loads and allowing you to get more requests per second.

You can apply our selected tweaks by pasting the below into your /etc/sysctl.conf file, and then running  sysctl -p" to apply the changes.

# Increase the max OS recv/send buffer size
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

# Increase the connection track table size
net.ipv4.netfilter.ip_conntrack_max = 999999

# Widen the local port range to allow more ports
net.ipv4.ip_local_port_range = 1024 65023

# Lower the TCPFIN timeout
net.ipv4.tcp_fin_timeout = 30

# Increase the max backlog, syn tweaks
net.core.netdev_max_backlog = 10000
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_synack_retries = 3

# Enable syn cookies vs syn floods, RP filter
net.ipv4.tcp_syncookies = 1
net.ipv4.conf.all.rp_filter = 1

# Increase to handle spikes of traffic
net.core.somaxconn = 60000

# Increase the TIME WAIT buckets pool size for DoS/performance
net.ipv4.tcp_max_tw_buckets = 1440000
net.ipv4.tcp_tw_reuse = 1

# Adjust TCP orphan limit
net.ipv4.tcp_max_orphans = 262144

If any give you an error it may be because of a kernel version or anything else, just remove the relevant line. Remember to reboot or run sysctl -p” to apply this.

Haproxy.cfg Config Changes

Below are several tips to keep in mind when creating or adjusting your haproxy.cfg file.

Mode Selection

TCP mode groups are much less load than HTTP. Check your "mode" setting under a listen, frontend, or backend section of the config. If you don't need to do any HTTP level adjustments then TCP mode will be much faster.

HTTP Tweaks

There are a lot of configuration changes that effect performance, but there are (as always) some easy tweaks to get more out of your server farm. Firstly, consider adding option httpclose to all your HTTP groups. In Snapt, this is called “Force HTTP Close.” This will stop keepalives, but that will be to your advantage. Also, add  option abortonclose – this will close aborted requests.

Maxconn Setting

HAProxy limits connections on a global level as well as a frontend/listen level to the maxconn setting. It restricts the maximum number of connections HAProxy will accept (at a time), so make sure it’s high enough. You can use this in groups as well as globally. In Snapt, this is called “Maximum Connections.”

Make sure you don't have it set high in the "global" section of the config, but not high enough in the "listen" or "frontend" section!

Balance Method

Only use what you require when choosing a balance method. Remember that roundrobin is going to be much faster, so if there is no requirement for a more advanced method don’t use it (in performance sensitive situations).

Compression

HTTP compression uses a lot of CPU, and if you are in a high-performance environment, you will want to disable it. This obviously has pluses and minuses.

HAProxy

Published at DZone with permission of Nadine Arnold. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Zero Trust, Build High Scale TLS Termination Layer
  • Close Site Search Indexing via Kubernetes HAProxy Ingress
  • Optimizing Server Management With HAProxy’s Advanced Health Checks
  • Implementing HTTP Load Balancer Using HAProxy on AWS

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook