Merge ~hloeung/content-cache-charm:tuning into content-cache-charm:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 0ab469989ede8d19eabb86d8b14c7e78e030ba44
Merged at revision: f6b26ecce970f34157b8c4a11182b8cd60b3a3d6
Proposed branch: ~hloeung/content-cache-charm:tuning
Merge into: content-cache-charm:master
Diff against target: 129 lines (+18/-8)
5 files modified
config.yaml (+5/-0)
lib/utils.py (+1/-3)
reactive/content_cache.py (+3/-1)
tests/unit/test_content_cache.py (+5/-0)
tests/unit/test_utils.py (+4/-4)
Reviewer Review Type Date Requested Status
Joel Sing (community) +1 Approve
Canonical IS Reviewers Pending
Review via email: mp+409803@code.launchpad.net

Commit message

Allow overriding the multiplier used to tune net.ipv4.tcp_mem. Also, default to something lower, 1.5 rather than 3

Description of the change

Follow up to https://code.launchpad.net/~hloeung/content-cache-charm/+git/content-cache-charm/+merge/409623 exposing the option to override the multiplier used to tune net.ipv4.tcp_mem

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Joel Sing (jsing) wrote :

LGTM

review: Approve (+1)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision f6b26ecce970f34157b8c4a11182b8cd60b3a3d6

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/config.yaml b/config.yaml
2index 84f8834..d9959ac 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -124,6 +124,11 @@ options:
6 type: string
7 description: >
8 Override default ciphers used for TLS/SSL termination (OpenSSL format).
9+ tune_tcp_mem_multiplier:
10+ type: float
11+ default: 1.5
12+ description: >
13+ Tune net.ipv4.tcp_mem, apply multiplier.
14 worker_connections:
15 default: 768
16 type: int
17diff --git a/lib/utils.py b/lib/utils.py
18index 34996b2..a21eb8a 100644
19--- a/lib/utils.py
20+++ b/lib/utils.py
21@@ -250,7 +250,7 @@ def select_tcp_congestion_control(preferred_tcp_cc, tcp_avail_path=_SYSCTL_NET_I
22 _SYSCTL_NET_IPV4_TCP_MEM = '/proc/sys/net/ipv4/tcp_mem'
23
24
25-def tune_tcp_mem(tcp_mem_path=_SYSCTL_NET_IPV4_TCP_MEM, mmap_pagesize=mmap.PAGESIZE):
26+def tune_tcp_mem(multiplier=1.5, tcp_mem_path=_SYSCTL_NET_IPV4_TCP_MEM, mmap_pagesize=mmap.PAGESIZE):
27
28 # For LXC/LXD containers, we can't tune tcp_mem.
29 if not os.path.exists(tcp_mem_path):
30@@ -271,6 +271,4 @@ def tune_tcp_mem(tcp_mem_path=_SYSCTL_NET_IPV4_TCP_MEM, mmap_pagesize=mmap.PAGES
31 mem_pressure = limit
32 mem_max = mem_min * 2
33
34- # Now triple it!
35- multiplier = 3
36 return "{} {} {}".format(int(mem_min * multiplier), int(mem_pressure * multiplier), int(mem_max * multiplier))
37diff --git a/reactive/content_cache.py b/reactive/content_cache.py
38index 96c3ea2..572086e 100644
39--- a/reactive/content_cache.py
40+++ b/reactive/content_cache.py
41@@ -469,6 +469,8 @@ _SYSCTL_CORE_DEFAULT_QDISC = '/proc/sys/net/core/default_qdisc'
42
43 @reactive.when_not('content_cache.sysctl.configured')
44 def configure_sysctl():
45+ config = hookenv.config()
46+
47 context = {
48 'net_core_default_qdisc': None,
49 'net_ipv4_tcp_congestion_control': None,
50@@ -479,7 +481,7 @@ def configure_sysctl():
51
52 preferred_tcp_cc = ['bbr2', 'bbr']
53 context['net_ipv4_tcp_congestion_control'] = utils.select_tcp_congestion_control(preferred_tcp_cc)
54- context['net_ipv4_tcp_mem'] = utils.tune_tcp_mem()
55+ context['net_ipv4_tcp_mem'] = utils.tune_tcp_mem(config['tune_tcp_mem_multiplier'])
56
57 # Set or lower tcp_notsent_lowat to optimise HTTP/2 prioritisation.
58 # https://blog.cloudflare.com/http-2-prioritization-with-nginx/
59diff --git a/tests/unit/test_content_cache.py b/tests/unit/test_content_cache.py
60index 56804ad..2d3cd61 100644
61--- a/tests/unit/test_content_cache.py
62+++ b/tests/unit/test_content_cache.py
63@@ -1158,6 +1158,7 @@ site1.local:
64 @mock.patch('lib.utils.tune_tcp_mem')
65 def test_configure_sysctl(self, tune_tcp_mem, tcp_cc, call, set_flag):
66 sysctl_conf_path = os.path.join(self.tmpdir, '90-content-cache.conf')
67+ self.mock_config.return_value = {'tune_tcp_mem_multiplier': 1.5}
68 tune_tcp_mem.return_value = None
69 tcp_cc.return_value = None
70
71@@ -1187,6 +1188,7 @@ site1.local:
72 @mock.patch('lib.utils.tune_tcp_mem')
73 def test_configure_sysctl_all(self, tune_tcp_mem, tcp_cc, call, set_flag):
74 sysctl_conf_path = os.path.join(self.tmpdir, '90-content-cache.conf')
75+ self.mock_config.return_value = {'tune_tcp_mem_multiplier': 1.5}
76
77 # Test with all 3, qdisc, tcp_congestion_control, and tcp_mem
78 tune_tcp_mem.return_value = '92430 123242 184860'
79@@ -1212,6 +1214,7 @@ site1.local:
80 @mock.patch('lib.utils.tune_tcp_mem')
81 def test_configure_sysctl_default_qdisc(self, tune_tcp_mem, tcp_cc, call, set_flag):
82 sysctl_conf_path = os.path.join(self.tmpdir, '90-content-cache.conf')
83+ self.mock_config.return_value = {'tune_tcp_mem_multiplier': 1.5}
84 tune_tcp_mem.return_value = None
85 tcp_cc.return_value = None
86
87@@ -1248,6 +1251,7 @@ site1.local:
88 @mock.patch('lib.utils.tune_tcp_mem')
89 def test_configure_sysctl_tcp_congestion_control(self, tune_tcp_mem, tcp_cc, call, set_flag):
90 sysctl_conf_path = os.path.join(self.tmpdir, '90-content-cache.conf')
91+ self.mock_config.return_value = {'tune_tcp_mem_multiplier': 1.5}
92 tune_tcp_mem.return_value = None
93 qdisc_path = 'some-file-does-not-exist'
94
95@@ -1296,6 +1300,7 @@ site1.local:
96 @mock.patch('lib.utils.tune_tcp_mem')
97 def test_configure_sysctl_tcp_mem(self, tune_tcp_mem, tcp_cc, call, set_flag):
98 sysctl_conf_path = os.path.join(self.tmpdir, '90-content-cache.conf')
99+ self.mock_config.return_value = {'tune_tcp_mem_multiplier': 1.5}
100 tcp_cc.return_value = None
101 qdisc_path = 'some-file-does-not-exist'
102
103diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
104index 062f506..16434d1 100644
105--- a/tests/unit/test_utils.py
106+++ b/tests/unit/test_utils.py
107@@ -238,18 +238,18 @@ class TestLibUtils(unittest.TestCase):
108 svmem.total = 541071241216
109 virtual_memory.return_value = svmem
110 want = '18353292 24471056 36706584'
111- self.assertEqual(utils.tune_tcp_mem(mmap_pagesize=4096), want)
112+ self.assertEqual(utils.tune_tcp_mem(3, mmap_pagesize=4096), want)
113
114 svmem.total = 8230563840
115 virtual_memory.return_value = svmem
116 want = '279183 372244 558366'
117- self.assertEqual(utils.tune_tcp_mem(mmap_pagesize=4096), want)
118+ self.assertEqual(utils.tune_tcp_mem(3, mmap_pagesize=4096), want)
119
120 svmem.total = 541071241216
121 virtual_memory.return_value = svmem
122 want = '9176646 12235528 18353292'
123- self.assertEqual(utils.tune_tcp_mem(mmap_pagesize=8192), want)
124+ self.assertEqual(utils.tune_tcp_mem(3, mmap_pagesize=8192), want)
125
126 sysctl_tcp_mem_path = 'some-file-does-not-exist'
127 want = None
128- self.assertEqual(utils.tune_tcp_mem(sysctl_tcp_mem_path), want)
129+ self.assertEqual(utils.tune_tcp_mem(tcp_mem_path=sysctl_tcp_mem_path), want)

Subscribers

People subscribed via source and target branches