Skip to content

Commit eea6ac6

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Optimize HAProxy SSL cache size"
2 parents d90ea57 + 454cff5 commit eea6ac6

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

octavia/common/jinja/haproxy/combined_listeners/jinja_cfg.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ def render_loadbalancer_obj(self, host_amphora, listeners,
187187
constants.INSECURE_FORK)
188188
enable_prometheus = prometheus_listener and feature_compatibility.get(
189189
lib_consts.PROTOCOL_PROMETHEUS, False)
190+
term_https_listener = any(
191+
lsnr.protocol == lib_consts.PROTOCOL_TERMINATED_HTTPS for lsnr in
192+
listeners)
190193

191194
jinja_dict = {
192195
'loadbalancer': loadbalancer,
@@ -209,6 +212,25 @@ def render_loadbalancer_obj(self, host_amphora, listeners,
209212
except (KeyError, TypeError):
210213
pass
211214

215+
if term_https_listener:
216+
try:
217+
mem = amp_details["memory"]
218+
# Account for 32 KB per established connection for each
219+
# pair of HAProxy network sockets. Use 1024 as fallback
220+
# because that is what ulimit -n typically returns.
221+
max_conn_mem_kb = 32 * loadbalancer.get(
222+
"global_connection_limit", 1024)
223+
# Use half of the remaining memory for SSL caches
224+
ssl_cache_mem_kb = (mem["free"] + mem["buffers"] +
225+
mem["cached"] - max_conn_mem_kb) // 2
226+
# A cache block uses about 200 bytes of data.
227+
# The HAProxy default of ssl_cache (20000) would take up
228+
# 4000 KB. We don't want to go below that.
229+
if ssl_cache_mem_kb > 4000:
230+
jinja_dict["ssl_cache"] = ssl_cache_mem_kb * 5
231+
except (KeyError, TypeError):
232+
pass
233+
212234
return self._get_template().render(
213235
jinja_dict, constants=constants, lib_consts=lib_consts)
214236

octavia/common/jinja/haproxy/combined_listeners/templates/base.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ global
2626
{% if loadbalancer.global_connection_limit is defined %}
2727
maxconn {{ loadbalancer.global_connection_limit }}
2828
{% endif %}
29+
{% if ssl_cache is defined %}
30+
tune.ssl.cachesize {{ ssl_cache }}
31+
{% endif %}
2932
{%- if cpu_count is defined and cpu_count > 1 %}
3033
nbthread {{ cpu_count - 1 }}
3134
cpu-map auto:1/1-{{ cpu_count - 1 }} 1-{{ cpu_count - 1 }}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
other:
3+
- |
4+
When a HTTPS termination listener gets configured, Octavia will tweak the
5+
HAProxy `tune.ssl.cachesize` setting to use about half of the available
6+
memory (free + buffers + cached) on the amphora minus the memory needed
7+
for network sockets based on the global max connections setting.
8+
This allows to make better reuse of existing SSL sessions and
9+
helps to lower the number of computationally expensive SSL handshakes.

0 commit comments

Comments
 (0)