Document timing of task.create/delete in code

This commit is contained in:
Klaas van Schelven
2025-04-17 10:16:43 +02:00
parent 89927c7ab4
commit 7616b0ea77
2 changed files with 2 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ def shared_task(function):
# No need for a transaction: we just write something (not connected to any other object, and we will never # No need for a transaction: we just write something (not connected to any other object, and we will never
# touch it again). Counterpoint: if we'd have a transaction, we could distinguish between "wait for write # touch it again). Counterpoint: if we'd have a transaction, we could distinguish between "wait for write
# lock" and "actually write". # lock" and "actually write".
# observed timings: ~2.8ms, see also: https://www.bugsink.com/blog/snappea-design/#throughput
kwargs.update(add_task_kwargs()) kwargs.update(add_task_kwargs())
Task.objects.create(task_name=name, args=json.dumps(args), kwargs=json.dumps(kwargs)) Task.objects.create(task_name=name, args=json.dumps(args), kwargs=json.dumps(kwargs))

View File

@@ -343,6 +343,7 @@ class Foreman:
# (see 'counterpoint' in decorators.py for a counterpoint) # (see 'counterpoint' in decorators.py for a counterpoint)
# * delete-before-run is the implementation of our at-most-once guarantee # * delete-before-run is the implementation of our at-most-once guarantee
with time_to_logger(performance_logger, "Snappea Task.delete()"): with time_to_logger(performance_logger, "Snappea Task.delete()"):
# observed timings: ~1.5ms, see also: https://www.bugsink.com/blog/snappea-design/#throughput
task.delete() task.delete()
self.run_in_thread(task_id, function, *args, **kwargs) self.run_in_thread(task_id, function, *args, **kwargs)