大网数据广告活动
服务器运维问答

What is .max_connections parameter in varnish vcl and how to caculate this value for backend nginx server

· 52CE 我爱测

I have seen .max_connections parameter in varnish default.vcl and by seraching in web, found the artile below .max_connections : how many connections you authorize Varnish to open to this backend. Remember that connections are po…

问题原文

原帖链接 · Md. Shahriar Hossain · CC BY-SA 4.0

I have seen .max_connections parameter in varnish default.vcl and by seraching in web, found the artile below .max_connections: how many connections you authorize Varnish to open to this backend. Remember that connections are pooled and reused, so your backend should have an easier life anyway, but sometimes, you need to protect it even more. Be careful though because that is a hard limit, and if it is reached, Varnish won't use this backend, even if it means returning an error to the user.

Now, I want to know if max connection means request/sec or concurrent user or anything else. How will I calculate it for a backend nginx server?

已采纳解答

原帖链接 · Thijs Feryn · CC BY-SA 4.0

The need for multiple backend connections

In HTTP/1.1 there is no request multiplexing on a single connection. If there's multiple requests to Varnish at the same time, for resources that aren't stored in cache, multiple backend connections might be opened up.

Varnish will keep connections open to the backend and re-use them for other requests. Varnish will also perform request coalescing and collapse backend requests for the same resource.

That being said, there are still situations where Varnish needs to open up multiple connections to a single backend.

Limiting backend connections

Depending on the amount of traffic your platform gets, depending on the hit rate of your cache, and the resources that your backend servers have, you might want to limit the connections to the backend.

The idea of using Varnish, is to avoid excessive connections to your origin servers. By introducing max_connections in your backend definition, you can protect your origin from excessive revalidation in Varnish.

If your hit rate is decent, you will never hit that limit, but if you do max_connections will ensure fetches get queued until a connection gets freed up.

Calculating max_connections

max_connections is there to prevent your server from going out of memory.

The value you're going to choose depends on the amount of resources your origin server has, and the average time it takes to satisfy a request.

You can perform a load test using ab or siege and figure out how many simultaneous connections your origin can handle before going into high load.

Please make sure keepalive is turned off during those tests

It's very much trial and error. Make sure that your initial max_connections value is way too high, send enough traffic, and look for the tipping point.

Lower the value of max_connections, rinse, repeat.

Once you figured out the max_connections setting for your origin, keep it in the webserver configuratino of your origin (Apache or Nginx).

Eventually, you'll also set that value in your Varnish backend definition.

The idea is that Varnish shouldn't allow more simultaneous connections to your backend servers, than what they're configured to handle.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-08-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。