22
33## Overview
44
5- Welcome to the TokenGate Beta documentation! This document provides an overview of the current state of the
6- TokenGate project, including its features, limitations, and future plans. I also include a quick startup guide
7- for both the WebSocket and regular operations. Please note that this is a beta version, and while it is
8- stable and actively tested, edge cases and rough spots are expected at this stage.
5+ Welcome to the TokenGate Beta documentation!
96
7+ This document provides an overview of the current state of TokenGate.
108
119### Current Features
1210
1311- ** Token based concurrency:** The core feature of TokenGate is its token-based concurrency model, which
14- allows for efficient coordination of tasks across multiple threads.
12+ allows for efficient coordination of tasks across multiple threads.
1513- ** WebSocket support:** TokenGate includes support for WebSocket communication, enabling real-time
1614 monitoring and control of tasks.
17- - *** DoS protection* :** The token system includes built-in DoS protection ("auto-blocking") to prevent overwhelming
15+ - ** DoS protection:** The token system includes built-in DoS protection ("auto-blocking") to prevent overwhelming
1816 the system with too many "failed" concurrent tasks. (Tasks which do not return their result are "failed".)
1917- ** Telemetry:** TokenGate provides telemetry data for tasks, allowing for monitoring and debugging of concurrent
2018 operations with clarity.
19+ - ** Flexible API:** The API is designed to be flexible and easy to use, allowing developers to quickly integrate
20+ TokenGate into their applications with minimal setup.
21+ - ** Token safety:** The system is designed to prevent data loss and ensure that tokens are properly managed
22+ based on hashing as well as controlled token locality.
2123
2224### Limitations
2325- ** Beta status:** As a beta project, TokenGate may have bugs or performance issues that have not yet been
2426 identified or resolved.
25- - ** Limited documentation:** The documentation is currently limited and may not cover all aspects of the
26- project in detail . I plan to expand the documentation as the project progresses.
27+ - ** Limited documentation:** The documentation is currently limited and does not cover all aspects of the
28+ project. I plan to expand the documentation as the project progresses.
2729- ** Performance under extreme load:** While TokenGate is designed to handle a high volume of tasks, its
28- performance under extreme load conditions needs long term analysis.
29-
30- ### Future Plans
31- - ** Improved documentation:** I plan to expand the documentation to provide more detailed information on how
32- to use TokenGate and its various features.
33- - ** Performance optimizations:** I will continue to optimize the performance of TokenGate, especially under
34- high load conditions.
35- - ** Additional features:** I am considering adding additional features such as task control mechanisms like
36- "reset token status" to adjust auto-blocking live and possible dristributed compute support in the future.
30+ performance under extreme load conditions needs long term analysis.
3731
3832## Get Started
3933
40- ### Detailed startup guide:
41-
42- #### Using OperationsCoordinator without WebSocket:
34+ ### Using OperationsCoordinator event bus * without* WebSocket:
4335``` python
4436from operations_coordinator import OperationsCoordinator # Must accompany main()
4537from token_system import task_token_guard # The independent imported decorator for your functions
@@ -68,28 +60,81 @@ def string_operation_task(task_data):
6860# Setting up an IO-centric method with the token decorator:
6961# IO writer counts for 'storage_speed':
7062# 'SLOW' (10 writes), 'MODERATE'(25 writes),
71- # 'FAST' (50 writes), 'INSANE' (70 writes) <- CAUTION
72- @task_token_guard (operation_type = ' data_processing' , tags = {' weight' : ' heavy' , ' storage_speed' : ' MODERATE' })
63+ # 'FAST' (50 writes), 'INSANE' (70 writes) <- CAUTION only top-end SSDs will handle this.
64+ @task_token_guard (
65+ operation_type = ' data_processing' ,
66+ tags = {' weight' : ' heavy' , ' storage_speed' : ' MODERATE' }
67+ )
7368def data_processing_task (task_data ):
7469 # Simulate a data processing task
7570 return result
71+
72+
73+ # -----------------------------------NEW*-----------------------------------
74+ # As of v0.2.2.0-beta Awaiting tokens is supported, allowing for more complex
75+ # orchestration patterns. "result = await token" works to await a single token.
76+
77+ # Or a full batch can be awaited with asyncio.gather:
78+ async def main ():
79+ coordinator = OperationsCoordinator()
80+ coordinator.start()
81+ try :
82+ tokens = [my_task(i) for i in range (64 )]
83+ results = await asyncio.gather(* tokens)
84+ finally :
85+ coordinator.stop()
86+
87+ asyncio.run(main())
88+
89+ # -----------------------------------NEW------------------------------------
90+ # A "sticky_anchor" tag can be added to any decorator to give the sticky
91+ # key an explicit name, independent of operation type. Sticky tokens are
92+ # pinned to the same core domain and create a path for related operations
93+ # to follow the same route, ensuring data locality and consistent performance
94+ # even when the operations do not require this behavior to work.
95+
96+ # This happens automatically when the system interprets tokens with matching
97+ # (operation_type, args) keys.
98+ @task_token_guard (
99+ operation_type = " my_op" , # Use a unique operation type for clarity.
100+ tags = {" weight" : " medium" , " sticky_anchor" : " op_token" },
101+ # The 'sticky_anchor' tag gives this token a specific known moniker.
102+ # Good naming conventions for the sticky_anchor value can assist debugging.
103+ )
104+ def my_operation (n : int ) -> int :
105+ ...
106+
107+ # -----------------------------------NEW------------------------------------
108+ # "Lead tokens" — those decorated with 'external_calls' generate a SHA-256 seed from their
109+ # token ID and call list. That seed is pinned to a core domain. Any token spawned during
110+ # the lead's execution inherits the seed and gets routed to the same core automatically.
111+ # The domain releases when the lead and all of its children have completed. This is a
112+ # production ready feature that provides deterministic routing, prevents data races,
113+ # and measurably better behaviour under saturated load conditions for complex call chains.
114+ @task_token_guard (
115+ operation_type = " lead_op" ,
116+ tags = {" weight" : " medium" , " external_calls" : [" child_op" ]},
117+ )
118+ def lead_operation (n : int ) -> list :
119+ return [child_op(n + i) for i in range (4 )]
76120```
77121
78- #### Running the WebSocket server:
122+ ### Running the WebSocket server:
123+
79124``` bash
80125python launch_gui.py OR python -m your_package_root.launch_gui
81126```
82127* (Note: Adjust the path if running from outside the repository root).*
83128
84129
85- #### Using OperationsCoordinator with WebSocket:
130+ #### Using OperationsCoordinator * with* WebSocket:
86131``` python
87132from operations_coordinator import get_global_coordinator # Must accompany main()
88133
89134# Get coordinator (GUI already started it)
90135get_global_coordinator() # One line at module-level to rule the whole WebSocket!
91136
92- # No specific calls for main using the WebSocket
137+ # No specific calls for main using the WebSocket.
93138def main ():
94139 # Main is free now!
95140 try :
@@ -98,7 +143,7 @@ def main():
98143 pass
99144
100145if __name__ == " __main__" :
101- main() # This gets used by the entry point in the WebSocket launcher to route 'func' (function)!! !
146+ main() # This gets used by the entry point in the WebSocket launcher to route 'func'!
102147
103148# Decorated functions will use task_token_guard and the WebSocket integration will
104149# detect when the coordinated main is running to track task submissions.
@@ -126,8 +171,6 @@ When you first set up your WebSocket environment and want to run a task, you sho
126171- ** Task Launcher:** Your registered task should appear in the task launcher with its description and category.
127172![ Task Launcher] ( /assets/task_launcher.png )
128173
129-
130-
131174- ** Controls:** When you run the task, there is controls where you can monitor and manage it (e.g., stop, restart).
132175![ Admin Dashboard] ( /assets/per_operation_controls.png )
133176
@@ -137,8 +180,9 @@ When you first set up your WebSocket environment and want to run a task, you sho
137180
138181## Conclusion
139182
140- TokenGate is an active beta project that aims to provide a powerful and flexible concurrency management system
141- using tokens. While it is currently functional, there are still areas for improvement and optimization. I encourage
142- users to explore the project, provide feedback, and contribute to its development. 📦 🚀
183+ TokenGate is an active beta project that aims to provide a powerful and flexible production ready
184+ concurrency management system using tokens. While it is currently functional, there are still areas for
185+ improvement and optimization. I encourage users to explore the project, provide feedback, and contribute
186+ to its development. 📦 🚀
143187
144- To quickly reach out to the developers go here and drop a message (all forms of feedback are accepted) : [ Tavari] ( https://www.tavari.online )
188+ To quickly reach out go here and drop a review in the feedback section : [ Tavari] ( https://www.tavari.online )
0 commit comments