dbos 1.7.0a2__py3-none-any.whl → 1.7.0a3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
dbos/_queue.py CHANGED
@@ -1,3 +1,4 @@
1
+ import random
1
2
  import threading
2
3
  from typing import TYPE_CHECKING, Any, Callable, Coroutine, Optional, TypedDict
3
4
 
@@ -94,8 +95,12 @@ class Queue:
94
95
 
95
96
 
96
97
  def queue_thread(stop_event: threading.Event, dbos: "DBOS") -> None:
98
+ polling_interval = 1.0
99
+ min_polling_interval = 1.0
100
+ max_polling_interval = 120.0
97
101
  while not stop_event.is_set():
98
- if stop_event.wait(timeout=1):
102
+ # Wait for the polling interval with jitter
103
+ if stop_event.wait(timeout=polling_interval * random.uniform(0.95, 1.05)):
99
104
  return
100
105
  queues = dict(dbos._registry.queue_info_map)
101
106
  for _, queue in queues.items():
@@ -106,12 +111,22 @@ def queue_thread(stop_event: threading.Event, dbos: "DBOS") -> None:
106
111
  for id in wf_ids:
107
112
  execute_workflow_by_id(dbos, id)
108
113
  except OperationalError as e:
109
- # Ignore serialization error
110
- if not isinstance(
114
+ if isinstance(
111
115
  e.orig, (errors.SerializationFailure, errors.LockNotAvailable)
112
116
  ):
117
+ # If a serialization error is encountered, increase the polling interval
118
+ polling_interval = min(
119
+ max_polling_interval,
120
+ polling_interval * 2.0,
121
+ )
122
+ dbos.logger.warning(
123
+ f"Contention detected in queue thread for {queue.name}. Increasing polling interval to {polling_interval:.2f}."
124
+ )
125
+ else:
113
126
  dbos.logger.warning(f"Exception encountered in queue thread: {e}")
114
127
  except Exception as e:
115
128
  if not stop_event.is_set():
116
129
  # Only print the error if the thread is not stopping
117
130
  dbos.logger.warning(f"Exception encountered in queue thread: {e}")
131
+ # Attempt to scale back the polling interval on each iteration
132
+ polling_interval = max(min_polling_interval, polling_interval * 0.9)
dbos/_sys_db.py CHANGED
@@ -1650,7 +1650,7 @@ class SystemDatabase:
1650
1650
  return []
1651
1651
 
1652
1652
  # Compute max_tasks, the number of workflows that can be dequeued given local and global concurrency limits,
1653
- max_tasks = float("inf")
1653
+ max_tasks = 100 # To minimize contention with large queues, never dequeue more than 100 tasks
1654
1654
  if queue.worker_concurrency is not None or queue.concurrency is not None:
1655
1655
  # Count how many workflows on this queue are currently PENDING both locally and globally.
1656
1656
  pending_tasks_query = (
@@ -1694,6 +1694,7 @@ class SystemDatabase:
1694
1694
 
1695
1695
  # Retrieve the first max_tasks workflows in the queue.
1696
1696
  # Only retrieve workflows of the local version (or without version set)
1697
+ skip_locks = queue.concurrency is None
1697
1698
  query = (
1698
1699
  sa.select(
1699
1700
  SystemSchema.workflow_status.c.workflow_uuid,
@@ -1711,7 +1712,10 @@ class SystemDatabase:
1711
1712
  SystemSchema.workflow_status.c.application_version.is_(None),
1712
1713
  )
1713
1714
  )
1714
- .with_for_update(nowait=True) # Error out early
1715
+ # Unless global concurrency is set, use skip_locked to only select
1716
+ # rows that can be locked. If global concurrency is set, use no_wait
1717
+ # to ensure all processes have a consistent view of the table.
1718
+ .with_for_update(skip_locked=skip_locks, nowait=(not skip_locks))
1715
1719
  )
1716
1720
  if queue.priority_enabled:
1717
1721
  query = query.order_by(
@@ -1720,9 +1724,7 @@ class SystemDatabase:
1720
1724
  )
1721
1725
  else:
1722
1726
  query = query.order_by(SystemSchema.workflow_status.c.created_at.asc())
1723
- # Apply limit only if max_tasks is finite
1724
- if max_tasks != float("inf"):
1725
- query = query.limit(int(max_tasks))
1727
+ query = query.limit(int(max_tasks))
1726
1728
 
1727
1729
  rows = c.execute(query).fetchall()
1728
1730
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dbos
3
- Version: 1.7.0a2
3
+ Version: 1.7.0a3
4
4
  Summary: Ultra-lightweight durable execution in Python
5
5
  Author-Email: "DBOS, Inc." <contact@dbos.dev>
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
- dbos-1.7.0a2.dist-info/METADATA,sha256=cv0iRmtSfwgBhECvLi62ErKrKa0hbM4KW2YPX3UL4-A,13267
2
- dbos-1.7.0a2.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
- dbos-1.7.0a2.dist-info/entry_points.txt,sha256=_QOQ3tVfEjtjBlr1jS4sHqHya9lI2aIEIWkz8dqYp14,58
4
- dbos-1.7.0a2.dist-info/licenses/LICENSE,sha256=VGZit_a5-kdw9WT6fY5jxAWVwGQzgLFyPWrcVVUhVNU,1067
1
+ dbos-1.7.0a3.dist-info/METADATA,sha256=9JR52XmoJqAM8nBVORsnsYk2VnKr0TRjZs6H4pdJHGc,13267
2
+ dbos-1.7.0a3.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
+ dbos-1.7.0a3.dist-info/entry_points.txt,sha256=_QOQ3tVfEjtjBlr1jS4sHqHya9lI2aIEIWkz8dqYp14,58
4
+ dbos-1.7.0a3.dist-info/licenses/LICENSE,sha256=VGZit_a5-kdw9WT6fY5jxAWVwGQzgLFyPWrcVVUhVNU,1067
5
5
  dbos/__init__.py,sha256=NssPCubaBxdiKarOWa-wViz1hdJSkmBGcpLX_gQ4NeA,891
6
6
  dbos/__main__.py,sha256=G7Exn-MhGrVJVDbgNlpzhfh8WMX_72t3_oJaFT9Lmt8,653
7
7
  dbos/_admin_server.py,sha256=86rL_aQmmi_zZ4a7PGVNbF6ey9tP27WC1wazQedFLWo,15927
@@ -40,7 +40,7 @@ dbos/_migrations/versions/d994145b47b6_consolidate_inputs.py,sha256=_J0jP247fuo6
40
40
  dbos/_migrations/versions/eab0cc1d9a14_job_queue.py,sha256=uvhFOtqbBreCePhAxZfIT0qCAI7BiZTou9wt6QnbY7c,1412
41
41
  dbos/_migrations/versions/f4b9b32ba814_functionname_childid_op_outputs.py,sha256=m90Lc5YH0ZISSq1MyxND6oq3RZrZKrIqEsZtwJ1jWxA,1049
42
42
  dbos/_outcome.py,sha256=Kz3aL7517q9UEFTx3Cq9zzztjWyWVOx_08fZyHo9dvg,7035
43
- dbos/_queue.py,sha256=Kq7aldTDLRF7cZtkXmsCy6wV2PR24enkhghEG25NtaU,4080
43
+ dbos/_queue.py,sha256=0kJTPwXy3nZ4Epzt-lHky9M9S4L31645drPGFR8fIJY,4854
44
44
  dbos/_recovery.py,sha256=TBNjkmSEqBU-g5YXExsLJ9XoCe4iekqtREsskXZECEg,2507
45
45
  dbos/_registrations.py,sha256=U-PwDZBuyuJjA2LYtud7D3VxDR440mVpMYE-S11BWDo,7369
46
46
  dbos/_roles.py,sha256=kCuhhg8XLtrHCgKgm44I0abIRTGHltf88OwjEKAUggk,2317
@@ -49,7 +49,7 @@ dbos/_schemas/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
49
  dbos/_schemas/application_database.py,sha256=SypAS9l9EsaBHFn9FR8jmnqt01M74d9AF1AMa4m2hhI,1040
50
50
  dbos/_schemas/system_database.py,sha256=rbFKggONdvvbb45InvGz0TM6a7c-Ux9dcaL-h_7Z7pU,4438
51
51
  dbos/_serialization.py,sha256=bWuwhXSQcGmiazvhJHA5gwhrRWxtmFmcCFQSDJnqqkU,3666
52
- dbos/_sys_db.py,sha256=yhwhH23QvehbhPW3k6f4TRQ6mDjmvMILqsR8YffFZBg,80368
52
+ dbos/_sys_db.py,sha256=PaWa5Y8ublSMqPQXCHvYqln01cGf2LtPdXaLEHJq500,80653
53
53
  dbos/_templates/dbos-db-starter/README.md,sha256=GhxhBj42wjTt1fWEtwNriHbJuKb66Vzu89G4pxNHw2g,930
54
54
  dbos/_templates/dbos-db-starter/__package/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
55
55
  dbos/_templates/dbos-db-starter/__package/main.py.dbos,sha256=aQnBPSSQpkB8ERfhf7gB7P9tsU6OPKhZscfeh0yiaD8,2702
@@ -69,4 +69,4 @@ dbos/cli/cli.py,sha256=IcfaX4rrSrk6f24S2jrlR33snYMyNyEIx_lNQtuVr2E,22081
69
69
  dbos/dbos-config.schema.json,sha256=CjaspeYmOkx6Ip_pcxtmfXJTn_YGdSx_0pcPBF7KZmo,6060
70
70
  dbos/py.typed,sha256=QfzXT1Ktfk3Rj84akygc7_42z0lRpCq0Ilh8OXI6Zas,44
71
71
  version/__init__.py,sha256=L4sNxecRuqdtSFdpUGX3TtBi9KL3k7YsZVIvv-fv9-A,1678
72
- dbos-1.7.0a2.dist-info/RECORD,,
72
+ dbos-1.7.0a3.dist-info/RECORD,,
File without changes