mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Fix a bug in background updates wherein background updates are never run using the default batch size (#12157)
This commit is contained in:
parent
f63bedef07
commit
26211fec24
1
changelog.d/12157.bugfix
Normal file
1
changelog.d/12157.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix a bug introduced in #4864 whereby background updates are never run with the default background batch size.
|
@ -102,10 +102,12 @@ class BackgroundUpdatePerformance:
|
|||||||
Returns:
|
Returns:
|
||||||
A duration in ms as a float
|
A duration in ms as a float
|
||||||
"""
|
"""
|
||||||
if self.avg_duration_ms == 0:
|
# We want to return None if this is the first background update item
|
||||||
return 0
|
if self.total_item_count == 0:
|
||||||
elif self.total_item_count == 0:
|
|
||||||
return None
|
return None
|
||||||
|
# Avoid dividing by zero
|
||||||
|
elif self.avg_duration_ms == 0:
|
||||||
|
return 0
|
||||||
else:
|
else:
|
||||||
# Use the exponential moving average so that we can adapt to
|
# Use the exponential moving average so that we can adapt to
|
||||||
# changes in how long the update process takes.
|
# changes in how long the update process takes.
|
||||||
|
@ -155,10 +155,10 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||||||
"current_updates": {
|
"current_updates": {
|
||||||
"master": {
|
"master": {
|
||||||
"name": "test_update",
|
"name": "test_update",
|
||||||
"average_items_per_ms": 0.001,
|
"average_items_per_ms": 0.1,
|
||||||
"total_duration_ms": 1000.0,
|
"total_duration_ms": 1000.0,
|
||||||
"total_item_count": (
|
"total_item_count": (
|
||||||
BackgroundUpdater.MINIMUM_BACKGROUND_BATCH_SIZE
|
BackgroundUpdater.DEFAULT_BACKGROUND_BATCH_SIZE
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -210,10 +210,10 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||||||
"current_updates": {
|
"current_updates": {
|
||||||
"master": {
|
"master": {
|
||||||
"name": "test_update",
|
"name": "test_update",
|
||||||
"average_items_per_ms": 0.001,
|
"average_items_per_ms": 0.1,
|
||||||
"total_duration_ms": 1000.0,
|
"total_duration_ms": 1000.0,
|
||||||
"total_item_count": (
|
"total_item_count": (
|
||||||
BackgroundUpdater.MINIMUM_BACKGROUND_BATCH_SIZE
|
BackgroundUpdater.DEFAULT_BACKGROUND_BATCH_SIZE
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -239,10 +239,10 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||||||
"current_updates": {
|
"current_updates": {
|
||||||
"master": {
|
"master": {
|
||||||
"name": "test_update",
|
"name": "test_update",
|
||||||
"average_items_per_ms": 0.001,
|
"average_items_per_ms": 0.1,
|
||||||
"total_duration_ms": 1000.0,
|
"total_duration_ms": 1000.0,
|
||||||
"total_item_count": (
|
"total_item_count": (
|
||||||
BackgroundUpdater.MINIMUM_BACKGROUND_BATCH_SIZE
|
BackgroundUpdater.DEFAULT_BACKGROUND_BATCH_SIZE
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -278,11 +278,9 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||||||
"current_updates": {
|
"current_updates": {
|
||||||
"master": {
|
"master": {
|
||||||
"name": "test_update",
|
"name": "test_update",
|
||||||
"average_items_per_ms": 0.001,
|
"average_items_per_ms": 0.05263157894736842,
|
||||||
"total_duration_ms": 2000.0,
|
"total_duration_ms": 2000.0,
|
||||||
"total_item_count": (
|
"total_item_count": (110),
|
||||||
2 * BackgroundUpdater.MINIMUM_BACKGROUND_BATCH_SIZE
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"enabled": True,
|
"enabled": True,
|
||||||
|
@ -66,13 +66,13 @@ class BackgroundUpdateTestCase(unittest.HomeserverTestCase):
|
|||||||
self.update_handler.reset_mock()
|
self.update_handler.reset_mock()
|
||||||
res = self.get_success(
|
res = self.get_success(
|
||||||
self.updates.do_next_background_update(False),
|
self.updates.do_next_background_update(False),
|
||||||
by=0.01,
|
by=0.02,
|
||||||
)
|
)
|
||||||
self.assertFalse(res)
|
self.assertFalse(res)
|
||||||
|
|
||||||
# on the first call, we should get run with the default background update size
|
# on the first call, we should get run with the default background update size
|
||||||
self.update_handler.assert_called_once_with(
|
self.update_handler.assert_called_once_with(
|
||||||
{"my_key": 1}, self.updates.MINIMUM_BACKGROUND_BATCH_SIZE
|
{"my_key": 1}, self.updates.DEFAULT_BACKGROUND_BATCH_SIZE
|
||||||
)
|
)
|
||||||
|
|
||||||
# second step: complete the update
|
# second step: complete the update
|
||||||
|
Loading…
Reference in New Issue
Block a user