Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7f9841b

Browse files
babolivierrichvdh
andauthoredNov 24, 2021
Lower minumum batch size to 1 for background updates (#11422)
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
1 parent f25c75d commit 7f9841b

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed
 

‎changelog.d/11422.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve performance of various background database schema updates.

‎synapse/storage/background_updates.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class BackgroundUpdater:
8282
process and autotuning the batch size.
8383
"""
8484

85-
MINIMUM_BACKGROUND_BATCH_SIZE = 100
85+
MINIMUM_BACKGROUND_BATCH_SIZE = 1
8686
DEFAULT_BACKGROUND_BATCH_SIZE = 100
8787
BACKGROUND_UPDATE_INTERVAL_MS = 1000
8888
BACKGROUND_UPDATE_DURATION_MS = 100

‎tests/rest/admin/test_background_updates.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from synapse.api.errors import Codes
2121
from synapse.rest.client import login
2222
from synapse.server import HomeServer
23+
from synapse.storage.background_updates import BackgroundUpdater
2324

2425
from tests import unittest
2526

@@ -150,9 +151,11 @@ def test_status_bg_update(self):
150151
"current_updates": {
151152
"master": {
152153
"name": "test_update",
153-
"average_items_per_ms": 0.1,
154+
"average_items_per_ms": 0.001,
154155
"total_duration_ms": 1000.0,
155-
"total_item_count": 100,
156+
"total_item_count": (
157+
BackgroundUpdater.MINIMUM_BACKGROUND_BATCH_SIZE
158+
),
156159
}
157160
},
158161
"enabled": True,
@@ -203,9 +206,11 @@ def test_enabled(self):
203206
"current_updates": {
204207
"master": {
205208
"name": "test_update",
206-
"average_items_per_ms": 0.1,
209+
"average_items_per_ms": 0.001,
207210
"total_duration_ms": 1000.0,
208-
"total_item_count": 100,
211+
"total_item_count": (
212+
BackgroundUpdater.MINIMUM_BACKGROUND_BATCH_SIZE
213+
),
209214
}
210215
},
211216
"enabled": False,
@@ -230,9 +235,11 @@ def test_enabled(self):
230235
"current_updates": {
231236
"master": {
232237
"name": "test_update",
233-
"average_items_per_ms": 0.1,
238+
"average_items_per_ms": 0.001,
234239
"total_duration_ms": 1000.0,
235-
"total_item_count": 100,
240+
"total_item_count": (
241+
BackgroundUpdater.MINIMUM_BACKGROUND_BATCH_SIZE
242+
),
236243
}
237244
},
238245
"enabled": False,
@@ -267,9 +274,11 @@ def test_enabled(self):
267274
"current_updates": {
268275
"master": {
269276
"name": "test_update",
270-
"average_items_per_ms": 0.1,
277+
"average_items_per_ms": 0.001,
271278
"total_duration_ms": 2000.0,
272-
"total_item_count": 200,
279+
"total_item_count": (
280+
2 * BackgroundUpdater.MINIMUM_BACKGROUND_BATCH_SIZE
281+
),
273282
}
274283
},
275284
"enabled": True,

‎tests/storage/test_background_update.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def prepare(self, reactor, clock, homeserver):
1919
)
2020

2121
def test_do_background_update(self):
22-
# the time we claim each update takes
23-
duration_ms = 42
22+
# the time we claim it takes to update one item when running the update
23+
duration_ms = 4200
2424

2525
# the target runtime for each bg update
26-
target_background_update_duration_ms = 50000
26+
target_background_update_duration_ms = 5000000
2727

2828
store = self.hs.get_datastore()
2929
self.get_success(
@@ -57,7 +57,7 @@ async def update(progress, count):
5757

5858
# on the first call, we should get run with the default background update size
5959
self.update_handler.assert_called_once_with(
60-
{"my_key": 1}, self.updates.DEFAULT_BACKGROUND_BATCH_SIZE
60+
{"my_key": 1}, self.updates.MINIMUM_BACKGROUND_BATCH_SIZE
6161
)
6262

6363
# second step: complete the update

0 commit comments

Comments
 (0)
This repository has been archived.