multiloop 0.1.0__tar.gz → 0.1.2__tar.gz
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.
- {multiloop-0.1.0 → multiloop-0.1.2}/AGENTS.md +58 -11
- multiloop-0.1.2/CHANGELOG.md +84 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/CITATION.cff +2 -2
- {multiloop-0.1.0 → multiloop-0.1.2}/Cargo.lock +4 -183
- {multiloop-0.1.0 → multiloop-0.1.2}/Cargo.toml +1 -5
- multiloop-0.1.2/PKG-INFO +389 -0
- multiloop-0.1.2/README.md +361 -0
- multiloop-0.1.2/README_ZH.md +360 -0
- multiloop-0.1.2/benchmarks/bench_asgi_throughput.py +490 -0
- multiloop-0.1.2/benchmarks/bench_wrk_asgi.py +343 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/docs/API.md +3 -4
- {multiloop-0.1.0 → multiloop-0.1.2}/docs/API_ZH.md +3 -4
- {multiloop-0.1.0 → multiloop-0.1.2}/docs/CONCURRENCY.md +34 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/docs/CONCURRENCY_ZH.md +34 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/pyproject.toml +18 -3
- multiloop-0.1.2/src/http.rs +1286 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/lib.rs +54 -29
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/__init__.py +1 -1
- multiloop-0.1.2/src/multiloop/_http11.py +413 -0
- multiloop-0.1.2/src/multiloop/_lifespan.py +223 -0
- multiloop-0.1.2/src/multiloop/_websocket.py +484 -0
- multiloop-0.1.2/src/multiloop/asgi.py +144 -0
- multiloop-0.1.2/src/multiloop/cli.py +438 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/pool.py +7 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/primitives.py +19 -1
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/rwlock.py +108 -16
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/server.py +80 -52
- multiloop-0.1.2/src/multiloop/wsgi.py +748 -0
- multiloop-0.1.2/src/rwlock.rs +196 -0
- multiloop-0.1.2/src/websocket.rs +292 -0
- multiloop-0.1.2/tests/test_asgi_backpressure.py +71 -0
- multiloop-0.1.2/tests/test_asgi_lifespan_ws.py +781 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_cli.py +36 -1
- multiloop-0.1.2/tests/test_http_pipelining.py +70 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_server.py +12 -2
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_wsgi.py +94 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/uv.lock +1 -34
- multiloop-0.1.0/CHANGELOG.md +0 -39
- multiloop-0.1.0/PKG-INFO +0 -356
- multiloop-0.1.0/README.md +0 -328
- multiloop-0.1.0/README_ZH.md +0 -327
- multiloop-0.1.0/benchmarks/bench_asgi_throughput.py +0 -209
- multiloop-0.1.0/src/h2.rs +0 -359
- multiloop-0.1.0/src/http.rs +0 -61
- multiloop-0.1.0/src/multiloop/asgi.py +0 -784
- multiloop-0.1.0/src/multiloop/cli.py +0 -275
- multiloop-0.1.0/src/multiloop/wsgi.py +0 -311
- multiloop-0.1.0/tests/test_asgi_lifespan_ws.py +0 -551
- {multiloop-0.1.0 → multiloop-0.1.2}/.editorconfig +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/.github/FUNDING.yml +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/.github/dependabot.yml +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/.github/pull_request_template.md +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/.github/release-drafter.yml +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/.github/workflows/ci.yml +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/.github/workflows/publish.yml +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/.github/workflows/release-drafter.yml +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/.gitignore +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/.pre-commit-config.yaml +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/.python-version +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/CODEOWNERS +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/CODE_OF_CONDUCT.md +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/CONTRIBUTING.md +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/LICENSE +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/Makefile +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/SECURITY.md +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/benchmarks/bench_multithread_loops.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/benchmarks/benchmark_pull_model.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/build.rs +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/deny.toml +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/docs/CHOOSING.md +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/docs/CHOOSING_ZH.md +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/examples/00_pool_basics.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/examples/01_channels_select.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/examples/02_waitgroup_once.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/examples/03_taskgroup_timeout.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/examples/04_sync_primitives.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/examples/05_asgi_websocket.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/examples/06_wsgi_flask.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/examples/README.md +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/examples/README_ZH.md +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/rust-toolchain.toml +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/channel.rs +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/metrics.rs +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/__init__.pyi +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/_cancel.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/_channel_base.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/_logging.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/_metrics.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/_multiloop_core.pyi +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/_options.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/_rust.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/_sync.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/_taskgroup.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/context.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/exceptions.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/py.typed +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/multiloop/testing/__init__.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/pool.rs +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/src/waitgroup.rs +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/conftest.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_cancel_scope.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_channel.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_docs.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_free_threading.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_go_parity.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_logging.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_loop_factory.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_perf_regression.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_pool.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_regression_bugs.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_sync_condition_barrier.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_sync_lock_event.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_sync_primitives.py +0 -0
- {multiloop-0.1.0 → multiloop-0.1.2}/tests/test_taskgroup.py +0 -0
|
@@ -34,7 +34,7 @@ invariants, token conservation laws, and multi-thread signal forwarding**.
|
|
|
34
34
|
```
|
|
35
35
|
multiloop/
|
|
36
36
|
├── src/
|
|
37
|
-
│ ├── multiloop/ # Python package (
|
|
37
|
+
│ ├── multiloop/ # Python package (22 modules)
|
|
38
38
|
│ │ ├── __init__.py # Public API surface — start here
|
|
39
39
|
│ │ ├── pool.py # EventLoopThreadPool engine
|
|
40
40
|
│ │ ├── primitives.py # Channel, select_channel, AsyncWaitGroup, AsyncOnce
|
|
@@ -42,11 +42,14 @@ multiloop/
|
|
|
42
42
|
│ │ ├── _cancel.py # CancelScope, fail_after, move_on_after, shield
|
|
43
43
|
│ │ ├── _sync.py # Lock, Semaphore, Event, Condition, Barrier
|
|
44
44
|
│ │ ├── _taskgroup.py # TaskGroup, TaskHandle
|
|
45
|
-
│ │ ├── rwlock.py # AsyncRWMutex (async read-write lock)
|
|
46
|
-
│ │ ├── asgi.py # MultiloopASGIWorker (ASGI 3.0, Lifespan, WebSockets
|
|
45
|
+
│ │ ├── rwlock.py # AsyncRWMutex (async read-write lock, Rust-backed)
|
|
46
|
+
│ │ ├── asgi.py # MultiloopASGIWorker (ASGI 3.0, Lifespan, WebSockets)
|
|
47
|
+
│ │ ├── _http11.py # Http11Protocol (Rust SIMD httparse & fused TCP write)
|
|
48
|
+
│ │ ├── _websocket.py # WebSocketProtocol (Rust SIMD unmasking & RFC 6455)
|
|
49
|
+
│ │ ├── _lifespan.py # ASGILifespanManager (ASGI lifespan state machine)
|
|
47
50
|
│ │ ├── wsgi.py # MultiloopWSGIWorker (WSGI 1.0.1, PEP 3333 synchronous runner)
|
|
48
51
|
│ │ ├── cli.py # multiloop run CLI server runner
|
|
49
|
-
│ │ ├── server.py # ConnectionPinningServer (
|
|
52
|
+
│ │ ├── server.py # ConnectionPinningServer (platform-adaptive multi-core listener)
|
|
50
53
|
│ │ ├── _channel_base.py # Shared waiter deques, _wake_all, _wakeup_next
|
|
51
54
|
│ │ ├── _rust.py # _try_import_rust_class helper
|
|
52
55
|
│ │ ├── _metrics.py # MetricsCollector
|
|
@@ -59,10 +62,11 @@ multiloop/
|
|
|
59
62
|
│ ├── pool.rs # NativeWorkerPool & PollerGuard
|
|
60
63
|
│ ├── channel.rs # Channel, RawAsyncChannel (Anti-Barging FIFO)
|
|
61
64
|
│ ├── waitgroup.rs # RawAsyncWaitGroup & WaitGroupInner
|
|
62
|
-
│ ├──
|
|
63
|
-
│
|
|
65
|
+
│ ├── rwlock.rs # RawAsyncRWMutex (64-bit atomic state machine)
|
|
66
|
+
│ ├── websocket.rs # FastWebSocketParser & SIMD fast_websocket_unmask
|
|
67
|
+
│ └── http.rs # FastHttpParser (SIMD httparse & zero-alloc ASGI assembly)
|
|
64
68
|
├── tests/ # 27 test files (pytest + pytest-asyncio)
|
|
65
|
-
├── benchmarks/ #
|
|
69
|
+
├── benchmarks/ # 5 benchmark scripts (including bench_wrk_asgi.py)
|
|
66
70
|
├── examples/ # Runnable examples (python examples/00_*.py)
|
|
67
71
|
├── docs/
|
|
68
72
|
│ ├── API.md # Complete API reference
|
|
@@ -264,8 +268,10 @@ pops so no single worker greedily drains the global queue.
|
|
|
264
268
|
| `RawAsyncChannel` | `src/channel.rs` | parking_lot + PyO3 | Python-independent async channel core with anti-barging FIFO ordering protection |
|
|
265
269
|
| `AtomicMetrics` | `src/metrics.rs` | `std::sync::atomic` | 64-byte-padded per-worker counters (`active`, `completed`, `global_pull_count`, `park_count`, etc.) — prevents false sharing |
|
|
266
270
|
| `RawAsyncWaitGroup` | `src/waitgroup.rs` | parking_lot `Mutex<WaitGroupInner>` | Go-style atomic counter + generation + waiter list with single-mutex state machine |
|
|
267
|
-
| `
|
|
268
|
-
| `
|
|
271
|
+
| `RawAsyncRWMutex` | `src/rwlock.rs` | parking_lot `Mutex<RWMutexInner>` | 64-bit atomic state machine, writer-preference async read-write lock with cancellation cleanup |
|
|
272
|
+
| `FastHttpConnection` | `src/http.rs` | httparse + PyO3 | Stateful HTTP/1.1 & WebSocket connection state machine, RFC 9112 chunk parser, request smuggling defense & zero-alloc response serializer |
|
|
273
|
+
| `FastHttpParser` | `src/http.rs` | httparse | SIMD zero-copy HTTP/1.x header parser with 22 interned headers, zero-alloc path/value interning & PyBuffer zero-copy |
|
|
274
|
+
| `FastWebSocketParser` & `fast_websocket_unmask` | `src/websocket.rs` | PyO3 | 32-byte 4-way SIMD vectorization unmasking, Option<[u8; 4]> allocation-free mask parsing, and RFC 6455 frame header parsing |
|
|
269
275
|
|
|
270
276
|
### Python-side patterns
|
|
271
277
|
|
|
@@ -284,7 +290,7 @@ pops so no single worker greedily drains the global queue.
|
|
|
284
290
|
while re-acquiring the lock after being notified, it automatically forwards
|
|
285
291
|
the notification to the next waiter to conserve notification tokens.
|
|
286
292
|
|
|
287
|
-
###
|
|
293
|
+
### Thirteen non-obvious design decisions
|
|
288
294
|
|
|
289
295
|
These are the places where a change that looks like a simplification usually
|
|
290
296
|
breaks a real correctness or performance property. **Read each before modifying
|
|
@@ -330,7 +336,48 @@ the related code.**
|
|
|
330
336
|
The push side falls back from local to global when a per-worker channel is
|
|
331
337
|
full, preserving liveness. Drain phase validates all three sources (global queue,
|
|
332
338
|
private buffer, local channel) are completely empty before worker loop termination.
|
|
333
|
-
|
|
339
|
+
|
|
340
|
+
8. **Darwin vs Linux `SO_REUSEPORT` asymmetric routing trap** (`src/multiloop/server.py:99-130`):
|
|
341
|
+
Linux `SO_REUSEPORT` hashes 4-tuples across multiple listening sockets with kernel-level
|
|
342
|
+
load balancing. On macOS (Darwin/BSD), `SO_REUSEPORT` does not implement symmetric
|
|
343
|
+
hashing and routes 100% of loopback connections to the newest bound socket, causing
|
|
344
|
+
severe worker starvation and degrading multi-core throughput to single-worker limits (~50k QPS).
|
|
345
|
+
`server.py` restricts `SO_REUSEPORT` to Linux only; on macOS/Darwin, workers share a single
|
|
346
|
+
listening socket and race concurrently on `loop.sock_accept(shared_sock)`, guaranteeing
|
|
347
|
+
perfect 25% load distribution and ~96k+ multi-core QPS.
|
|
348
|
+
|
|
349
|
+
9. **Python 3.14t Free-Threaded memory safety via `PyBytes::new_with`** (`src/websocket.rs:80-110`, `src/http.rs`):
|
|
350
|
+
Under Python 3.14t (No-GIL), modifying Python buffer objects in-place across threads
|
|
351
|
+
causes data races and invalidates Python's immutability invariant. Rust SIMD extensions must
|
|
352
|
+
allocate Python objects through atomic single-pass constructors like
|
|
353
|
+
`PyBytes::new_with(py, len, |buf| ...)` to populate unmasked payload bytes and serialized
|
|
354
|
+
HTTP responses without intermediate copies or in-place mutations.
|
|
355
|
+
|
|
356
|
+
10. **Unified Protocol Calculator (Rust) & Pure Transport Messenger (Python)** (`src/http.rs`, `_http11.py`):
|
|
357
|
+
`multiloop` strictly unifies HTTP/1.1 and WebSocket processing by eliminating parsing brain-split.
|
|
358
|
+
Rust `FastHttpConnection` owns 100% of protocol computation: SIMD header parsing, RFC 9112 chunked
|
|
359
|
+
streaming decoding with trailer verification, request smuggling defense (CL-TE/TE-TE rejection),
|
|
360
|
+
zero-allocation response wire serialization, and WebSocket frame fusion. Python `Http11Protocol` acts
|
|
361
|
+
purely as an asynchronous transport messenger (~380 lines), driving socket I/O, managing `_body_queue`
|
|
362
|
+
backpressure with `pump_events()` residue draining, and dispatching ASGI 3.0 coroutines.
|
|
363
|
+
|
|
364
|
+
11. **Worker EventLoop Network Disconnection Exception Filtering** (`src/multiloop/pool.py:230-240`):
|
|
365
|
+
During high-concurrency client disconnects or abrupt socket termination, background transport socket
|
|
366
|
+
buffer flushes in `_SelectorSocketTransport` trigger `BrokenPipeError`, `ConnectionResetError`, or
|
|
367
|
+
`ConnectionAbortedError` without an active awaiter. Custom loop exception handler intercepts and suppresses
|
|
368
|
+
these normal network disconnection events, preventing unretrieved Future logs while keeping unexpected
|
|
369
|
+
runtime bugs intact.
|
|
370
|
+
|
|
371
|
+
12. **Multi-Thread `server.close()` Task Set Snapshot Isolation** (`src/multiloop/server.py:290-305`):
|
|
372
|
+
Under Python 3.14t true physical multi-core execution, multiple worker threads concurrently finish
|
|
373
|
+
requests and discard tasks from `self._worker_conn_tasks` while `server.close()` iterates over them.
|
|
374
|
+
`server.py` snapshots task collections with `list(tasks)` and `list(self._worker_conn_tasks.values())`
|
|
375
|
+
to prevent `RuntimeError: Set changed size during iteration`.
|
|
376
|
+
|
|
377
|
+
13. **ASGI Lifespan State Isolation via `.copy()`** (`src/multiloop/_http11.py:170`, `src/multiloop/_websocket.py:133`):
|
|
378
|
+
To conform to the ASGI 3.0 specification and prevent cross-request context pollution (e.g. `request.state.user_id`
|
|
379
|
+
leaking between users) and multi-core dictionary write contention under Python 3.14t, `scope["state"]` is
|
|
380
|
+
instantiated via `self.lifespan_state.copy()`.
|
|
334
381
|
|
|
335
382
|
---
|
|
336
383
|
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.2] - 2026-08-21
|
|
9
|
+
|
|
10
|
+
### Added & Optimized
|
|
11
|
+
- **wrk High-Concurrency Multi-Core Benchmark Suite (`benchmarks/bench_wrk_asgi.py`)**:
|
|
12
|
+
- Production-grade wrk benchmark suite for physical multi-core scaling under Python 3.14t No-GIL.
|
|
13
|
+
- Achieves **151,366+ QPS** (4-Worker) on `/api/plaintext` and **145,836+ QPS** on `/api/ping` with sub-millisecond latency (0.29ms avg).
|
|
14
|
+
- **Rust SIMD HTTP Sliced Streaming & Zero-Allocation Fast-Path (`src/http.rs`, `src/multiloop/_http11.py`)**:
|
|
15
|
+
- `FastHttpConnection` streaming body sliced event dispatch (`ReceivingContentLength`) eliminating cursor rewind and $O(N^2)$ header re-parsing on split TCP packets.
|
|
16
|
+
- $O(1)$ buffer compaction via `compact_buffer` clearing on cursor drain without memory copies.
|
|
17
|
+
- Fast-path for zero-body GET/HEAD requests with module-level singleton `_EMPTY_BODY_MSG`, completely eliminating `asyncio.Queue` heap allocation and event loop dispatch overhead.
|
|
18
|
+
- **ASGI Transport Backpressure & Pipelining Concurrency Protection (`src/multiloop/_http11.py`, `src/multiloop/_websocket.py`)**:
|
|
19
|
+
- Physical write backpressure flow control (`_drain_event`) in `Http11Protocol.send()` eliminating server OOM under slow clients.
|
|
20
|
+
- Serial HTTP Pipelining request queueing (`_pending_pipeline_events`) guaranteeing strictly ordered, non-interleaved TCP responses.
|
|
21
|
+
- RFC 6455 WebSocket thread-safe send frame lock synchronization (`_send_lock`), eliminating `RuntimeError: concurrent drain calls` on high-concurrency data/control frame writes.
|
|
22
|
+
- **WSGI True Streaming Channel & Client Disconnect Decoupling (`src/multiloop/wsgi.py`)**:
|
|
23
|
+
- `SyncStreamReader` backed by lock-free cross-thread `Channel(maxsize=16)`, eliminating the 10MB pre-buffering requirement and enabling true streaming request body consumption.
|
|
24
|
+
- Automatic channel closure and feeder cancellation upon client disconnection, preventing orphaned synchronous WSGI worker tasks from occupying the thread pool.
|
|
25
|
+
- **No-GIL Task Collection Thread Safety & Adaptive CLI Watcher (`src/multiloop/server.py`, `src/multiloop/cli.py`)**:
|
|
26
|
+
- `ConnectionPinningServer` multi-worker task collection mutex protection (`_tasks_lock`), eliminating `RuntimeError: Set changed size during iteration` during `server.close()` under Python 3.14t physical multi-core execution.
|
|
27
|
+
- CLI file watcher with extended ignored directories and adaptive smooth polling backoff (0.3s~0.8s), reducing idle CPU usage while maintaining fast hot-reload responsiveness.
|
|
28
|
+
|
|
29
|
+
## [0.1.1] - 2026-08-18
|
|
30
|
+
|
|
31
|
+
### Added & Optimized
|
|
32
|
+
- **Pure-Python Cross-Platform ASGI Benchmark Engine (`benchmarks/bench_asgi_throughput.py`)**:
|
|
33
|
+
- Implemented high-performance multi-threaded HTTP/1.1 Keep-Alive raw socket load generator.
|
|
34
|
+
- 100% native on Windows, macOS, and Linux with zero external command dependencies (eliminated `ab` requirement).
|
|
35
|
+
- Achieves 70,000+ QPS with multi-core physical scaling across worker event loops.
|
|
36
|
+
- **Rust SIMD FastHttpParser & Zero-Allocation Assembly (`src/http.rs`)**:
|
|
37
|
+
- Direct ASGI `PyList[(PyBytes, PyBytes)]` tuple assembly in Rust C-layer, eliminating 20+ intermediate small-object allocations per HTTP request.
|
|
38
|
+
- Global `OnceLock<InternedMethods>` static interning for common HTTP verbs (`GET`, `POST`, `PUT`, `DELETE`, `PATCH`, `HEAD`, `OPTIONS`) and protocol versions (`1.0`, `1.1`, `2.0`), enabling zero-allocation method resolution across worker threads.
|
|
39
|
+
- **Rust SIMD RFC 6455 WebSocket Unmasking (`src/websocket.rs`, `src/multiloop/_websocket.py`)**:
|
|
40
|
+
- 64-bit auto-vectorized chunk XOR unmasking with `PyBytes::new_with` single-pass memory safety under Python 3.14t No-GIL.
|
|
41
|
+
- Zero-copy WebSocket frame header parser (`FastWebSocketParser::parse_frame_header`).
|
|
42
|
+
- **Rust `RawAsyncRWMutex` 64-Bit Atomic Core (`src/rwlock.rs`, `src/multiloop/rwlock.py`)**:
|
|
43
|
+
- 64-bit atomic state machine with writer-preference fairness.
|
|
44
|
+
- Cancellation token conservation and automatic waiter cleanup (`remove_waiter`), preventing cross-language GC reference leaks and writer-cancellation reader starvation.
|
|
45
|
+
- **Platform-Aware Multi-Core Connection Balancing (`src/multiloop/server.py`)**:
|
|
46
|
+
- Linux: Symmetric kernel-level `SO_REUSEPORT` 4-tuple BPF hash balancing across worker event loops.
|
|
47
|
+
- macOS / BSD: Multi-worker shared-socket racing accept (`loop.sock_accept(shared_sock)`) achieving perfectly balanced 25% traffic distribution per worker and 91,650+ QPS.
|
|
48
|
+
- **ASGI & FastAPI High-Throughput Benchmarks (`benchmarks/bench_asgi_throughput.py`)**:
|
|
49
|
+
- Real-world POST payload throughput increased from 34.1k to **83,168 req/s (+143% speedup)**.
|
|
50
|
+
- Ultra-lightweight JSON Ping stabilized at **91,125 ~ 91,653 req/s**.
|
|
51
|
+
- Multi-core CPU task dispatch achieving **3.65x physical speedup** on 4 workers (91.3% of theoretical limit).
|
|
52
|
+
|
|
53
|
+
## [0.1.0] - 2026-08-18
|
|
54
|
+
|
|
55
|
+
### Added
|
|
56
|
+
- **Multi-Event-Loop Engine (`EventLoopThreadPool`)**:
|
|
57
|
+
- Independent `asyncio` event loop running per worker OS thread under Python 3.14t free-threading (no GIL).
|
|
58
|
+
- Native Rust work-stealing shared queue architecture (`NativeWorkerPool`) with lock-free global flume queue and per-worker local channels.
|
|
59
|
+
- Soft poller gate (`num_polling < max(num_workers / 2, 1)`) and batch task pulling (`min(global_len / num_workers + 1, 128)`) to eliminate thundering herd contention.
|
|
60
|
+
- ContextVars preservation across thread hops (`contextvars.copy_context()`).
|
|
61
|
+
- **Go-Style Concurrency Primitives**:
|
|
62
|
+
- **`Channel`**: Lock-free channel backed by Rust core (`RawAsyncChannel`), supporting bounded/unbounded buffering, non-blocking `try_send`/`try_recv`, synchronous worker `send_sync`, and double-checked waiter lists.
|
|
63
|
+
- **`select_channel`**: Non-blocking randomized probe and single-future multi-registration arbiter for $O(1)$ first-ready channel selection.
|
|
64
|
+
- **`AsyncWaitGroup`**: Go-style atomic counter with generation tracking and leak-safe `track()`, `wrap()`, and `holding()` RAII context managers.
|
|
65
|
+
- **`AsyncOnce`**: Thread-safe single initialization runner across multi-loop environments.
|
|
66
|
+
- **`AsyncContext`**: Hierarchical cancellation context modeled after Go's `context.Context`.
|
|
67
|
+
- **Structured Concurrency**:
|
|
68
|
+
- **`TaskGroup`**: Nursery-style structured concurrency manager with automatic sibling cancellation on failure and non-blocking `start_soon` / synchronized `start`.
|
|
69
|
+
- **`CancelScope`**: Task-local cancellation scope with monotonic deadlines, shield snapshot/restore mechanics, and `fail_after`/`move_on_after` helpers.
|
|
70
|
+
- **Cross-Loop Synchronization Toolkit**:
|
|
71
|
+
- **`Lock`**: Fair FIFO async mutex bound to owning tasks.
|
|
72
|
+
- **`Semaphore`**: Fair FIFO async semaphore with token-conservative cancellation forwarding.
|
|
73
|
+
- **`CapacityLimiter`**: Dynamically resizable token capacity limiter with single-lock atomic state transitions.
|
|
74
|
+
- **`Event`**: One-shot cross-thread event with permanent set state.
|
|
75
|
+
- **`Condition`**: Async condition variable atop `Lock` with lock-free `notify()` to prevent notifier-sleeper deadlocks.
|
|
76
|
+
- **`Barrier`**: Synchronized N-party barrier with automatic round advancement and generation tracking.
|
|
77
|
+
- **`AsyncRWMutex`**: Asynchronous read-write lock with writer-preference fairness.
|
|
78
|
+
- **High-Performance Web Server Adapters & CLI**:
|
|
79
|
+
- **`ConnectionPinningServer`**: TCP server with Linux kernel-level `SO_REUSEPORT` 4-tuple hashing load balancing and connection affinity.
|
|
80
|
+
- **`MultiloopASGIWorker`**: ASGI 3.0 server adapter with Lifespan protocol, HTTP/1.1 chunked streaming, RFC 6455 WebSockets, and HTTP/2 Tokio runtime bridge (`_multiloop_core`).
|
|
81
|
+
- **`MultiloopWSGIWorker`**: WSGI 1.0.1 (PEP 3333) synchronous worker adapter for Flask and Django.
|
|
82
|
+
- **CLI Runner**: `multiloop run <module:app>` command with auto-reload and configurable worker counts.
|
|
83
|
+
- **Telemetry**:
|
|
84
|
+
- **`AtomicMetrics`**: 64-byte padded atomic counters preventing CPU cache-line false sharing.
|
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
# It is not intended for manual editing.
|
|
3
3
|
version = 4
|
|
4
4
|
|
|
5
|
-
[[package]]
|
|
6
|
-
name = "atomic-waker"
|
|
7
|
-
version = "1.1.2"
|
|
8
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
-
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
|
10
|
-
|
|
11
5
|
[[package]]
|
|
12
6
|
name = "bitflags"
|
|
13
7
|
version = "2.13.1"
|
|
@@ -20,24 +14,12 @@ version = "3.20.3"
|
|
|
20
14
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
15
|
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
|
|
22
16
|
|
|
23
|
-
[[package]]
|
|
24
|
-
name = "bytes"
|
|
25
|
-
version = "1.12.1"
|
|
26
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
-
checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
|
|
28
|
-
|
|
29
17
|
[[package]]
|
|
30
18
|
name = "cfg-if"
|
|
31
19
|
version = "1.0.4"
|
|
32
20
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
33
21
|
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
34
22
|
|
|
35
|
-
[[package]]
|
|
36
|
-
name = "equivalent"
|
|
37
|
-
version = "1.0.2"
|
|
38
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
39
|
-
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
|
40
|
-
|
|
41
23
|
[[package]]
|
|
42
24
|
name = "flume"
|
|
43
25
|
version = "0.11.1"
|
|
@@ -50,12 +32,6 @@ dependencies = [
|
|
|
50
32
|
"spin",
|
|
51
33
|
]
|
|
52
34
|
|
|
53
|
-
[[package]]
|
|
54
|
-
name = "fnv"
|
|
55
|
-
version = "1.0.7"
|
|
56
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
57
|
-
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
|
58
|
-
|
|
59
35
|
[[package]]
|
|
60
36
|
name = "futures-core"
|
|
61
37
|
version = "0.3.33"
|
|
@@ -99,69 +75,18 @@ dependencies = [
|
|
|
99
75
|
"wasm-bindgen",
|
|
100
76
|
]
|
|
101
77
|
|
|
102
|
-
[[package]]
|
|
103
|
-
name = "h2"
|
|
104
|
-
version = "0.4.15"
|
|
105
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
106
|
-
checksum = "6cb093c84e8bd9b188d4c4a8cb6579fc016968d14c99882163cd3ff402a4f155"
|
|
107
|
-
dependencies = [
|
|
108
|
-
"atomic-waker",
|
|
109
|
-
"bytes",
|
|
110
|
-
"fnv",
|
|
111
|
-
"futures-core",
|
|
112
|
-
"futures-sink",
|
|
113
|
-
"http",
|
|
114
|
-
"indexmap",
|
|
115
|
-
"slab",
|
|
116
|
-
"tokio",
|
|
117
|
-
"tokio-util",
|
|
118
|
-
"tracing",
|
|
119
|
-
]
|
|
120
|
-
|
|
121
|
-
[[package]]
|
|
122
|
-
name = "hashbrown"
|
|
123
|
-
version = "0.17.1"
|
|
124
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
125
|
-
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
|
126
|
-
|
|
127
78
|
[[package]]
|
|
128
79
|
name = "heck"
|
|
129
80
|
version = "0.5.0"
|
|
130
81
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
131
82
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
132
83
|
|
|
133
|
-
[[package]]
|
|
134
|
-
name = "http"
|
|
135
|
-
version = "1.5.0"
|
|
136
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
137
|
-
checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0"
|
|
138
|
-
dependencies = [
|
|
139
|
-
"bytes",
|
|
140
|
-
"itoa",
|
|
141
|
-
]
|
|
142
|
-
|
|
143
84
|
[[package]]
|
|
144
85
|
name = "httparse"
|
|
145
86
|
version = "1.10.1"
|
|
146
87
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
147
88
|
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
|
|
148
89
|
|
|
149
|
-
[[package]]
|
|
150
|
-
name = "indexmap"
|
|
151
|
-
version = "2.14.0"
|
|
152
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
153
|
-
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
|
|
154
|
-
dependencies = [
|
|
155
|
-
"equivalent",
|
|
156
|
-
"hashbrown",
|
|
157
|
-
]
|
|
158
|
-
|
|
159
|
-
[[package]]
|
|
160
|
-
name = "itoa"
|
|
161
|
-
version = "1.0.18"
|
|
162
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
163
|
-
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
|
164
|
-
|
|
165
90
|
[[package]]
|
|
166
91
|
name = "js-sys"
|
|
167
92
|
version = "0.3.103"
|
|
@@ -188,30 +113,15 @@ dependencies = [
|
|
|
188
113
|
"scopeguard",
|
|
189
114
|
]
|
|
190
115
|
|
|
191
|
-
[[package]]
|
|
192
|
-
name = "mio"
|
|
193
|
-
version = "1.2.2"
|
|
194
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
195
|
-
checksum = "30d65c71f1ce40ab09135ce117d742b9f8a19ff91a41a8b57ed50bc2de59c427"
|
|
196
|
-
dependencies = [
|
|
197
|
-
"libc",
|
|
198
|
-
"wasi",
|
|
199
|
-
"windows-sys",
|
|
200
|
-
]
|
|
201
|
-
|
|
202
116
|
[[package]]
|
|
203
117
|
name = "multiloop-core"
|
|
204
|
-
version = "0.1.
|
|
118
|
+
version = "0.1.2"
|
|
205
119
|
dependencies = [
|
|
206
|
-
"bytes",
|
|
207
120
|
"flume",
|
|
208
|
-
"h2",
|
|
209
|
-
"http",
|
|
210
121
|
"httparse",
|
|
211
122
|
"parking_lot",
|
|
212
123
|
"pyo3",
|
|
213
124
|
"pyo3-build-config",
|
|
214
|
-
"tokio",
|
|
215
125
|
]
|
|
216
126
|
|
|
217
127
|
[[package]]
|
|
@@ -315,7 +225,7 @@ dependencies = [
|
|
|
315
225
|
"proc-macro2",
|
|
316
226
|
"pyo3-macros-backend",
|
|
317
227
|
"quote",
|
|
318
|
-
"syn
|
|
228
|
+
"syn",
|
|
319
229
|
]
|
|
320
230
|
|
|
321
231
|
[[package]]
|
|
@@ -327,7 +237,7 @@ dependencies = [
|
|
|
327
237
|
"heck",
|
|
328
238
|
"proc-macro2",
|
|
329
239
|
"quote",
|
|
330
|
-
"syn
|
|
240
|
+
"syn",
|
|
331
241
|
]
|
|
332
242
|
|
|
333
243
|
[[package]]
|
|
@@ -372,16 +282,6 @@ version = "1.15.2"
|
|
|
372
282
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
373
283
|
checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90"
|
|
374
284
|
|
|
375
|
-
[[package]]
|
|
376
|
-
name = "socket2"
|
|
377
|
-
version = "0.6.5"
|
|
378
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
379
|
-
checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
|
|
380
|
-
dependencies = [
|
|
381
|
-
"libc",
|
|
382
|
-
"windows-sys",
|
|
383
|
-
]
|
|
384
|
-
|
|
385
285
|
[[package]]
|
|
386
286
|
name = "spin"
|
|
387
287
|
version = "0.9.9"
|
|
@@ -402,82 +302,12 @@ dependencies = [
|
|
|
402
302
|
"unicode-ident",
|
|
403
303
|
]
|
|
404
304
|
|
|
405
|
-
[[package]]
|
|
406
|
-
name = "syn"
|
|
407
|
-
version = "3.0.3"
|
|
408
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
409
|
-
checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
|
|
410
|
-
dependencies = [
|
|
411
|
-
"proc-macro2",
|
|
412
|
-
"quote",
|
|
413
|
-
"unicode-ident",
|
|
414
|
-
]
|
|
415
|
-
|
|
416
305
|
[[package]]
|
|
417
306
|
name = "target-lexicon"
|
|
418
307
|
version = "0.13.5"
|
|
419
308
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
420
309
|
checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
|
|
421
310
|
|
|
422
|
-
[[package]]
|
|
423
|
-
name = "tokio"
|
|
424
|
-
version = "1.53.1"
|
|
425
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
426
|
-
checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed"
|
|
427
|
-
dependencies = [
|
|
428
|
-
"bytes",
|
|
429
|
-
"libc",
|
|
430
|
-
"mio",
|
|
431
|
-
"pin-project-lite",
|
|
432
|
-
"socket2",
|
|
433
|
-
"tokio-macros",
|
|
434
|
-
"windows-sys",
|
|
435
|
-
]
|
|
436
|
-
|
|
437
|
-
[[package]]
|
|
438
|
-
name = "tokio-macros"
|
|
439
|
-
version = "2.7.2"
|
|
440
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
441
|
-
checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e"
|
|
442
|
-
dependencies = [
|
|
443
|
-
"proc-macro2",
|
|
444
|
-
"quote",
|
|
445
|
-
"syn 3.0.3",
|
|
446
|
-
]
|
|
447
|
-
|
|
448
|
-
[[package]]
|
|
449
|
-
name = "tokio-util"
|
|
450
|
-
version = "0.7.19"
|
|
451
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
452
|
-
checksum = "494815d09bf52b5548659851081238f0ca39ff638363907596da739561c62c52"
|
|
453
|
-
dependencies = [
|
|
454
|
-
"bytes",
|
|
455
|
-
"futures-core",
|
|
456
|
-
"futures-sink",
|
|
457
|
-
"libc",
|
|
458
|
-
"pin-project-lite",
|
|
459
|
-
"tokio",
|
|
460
|
-
]
|
|
461
|
-
|
|
462
|
-
[[package]]
|
|
463
|
-
name = "tracing"
|
|
464
|
-
version = "0.1.44"
|
|
465
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
466
|
-
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
|
|
467
|
-
dependencies = [
|
|
468
|
-
"pin-project-lite",
|
|
469
|
-
"tracing-core",
|
|
470
|
-
]
|
|
471
|
-
|
|
472
|
-
[[package]]
|
|
473
|
-
name = "tracing-core"
|
|
474
|
-
version = "0.1.36"
|
|
475
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
476
|
-
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
|
477
|
-
dependencies = [
|
|
478
|
-
"once_cell",
|
|
479
|
-
]
|
|
480
|
-
|
|
481
311
|
[[package]]
|
|
482
312
|
name = "unicode-ident"
|
|
483
313
|
version = "1.0.24"
|
|
@@ -522,7 +352,7 @@ dependencies = [
|
|
|
522
352
|
"bumpalo",
|
|
523
353
|
"proc-macro2",
|
|
524
354
|
"quote",
|
|
525
|
-
"syn
|
|
355
|
+
"syn",
|
|
526
356
|
"wasm-bindgen-shared",
|
|
527
357
|
]
|
|
528
358
|
|
|
@@ -540,12 +370,3 @@ name = "windows-link"
|
|
|
540
370
|
version = "0.2.1"
|
|
541
371
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
542
372
|
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
|
543
|
-
|
|
544
|
-
[[package]]
|
|
545
|
-
name = "windows-sys"
|
|
546
|
-
version = "0.61.2"
|
|
547
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
548
|
-
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
|
549
|
-
dependencies = [
|
|
550
|
-
"windows-link",
|
|
551
|
-
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "multiloop-core"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.2"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
|
|
@@ -13,10 +13,6 @@ pyo3 = "0.29"
|
|
|
13
13
|
flume = "0.11"
|
|
14
14
|
parking_lot = "0.12"
|
|
15
15
|
httparse = "1.10.1"
|
|
16
|
-
h2 = "0.4.15"
|
|
17
|
-
http = "1.5.0"
|
|
18
|
-
bytes = "1.12.1"
|
|
19
|
-
tokio = { version = "1.53.1", features = ["rt", "rt-multi-thread", "net", "io-util", "macros", "sync"] }
|
|
20
16
|
|
|
21
17
|
[build-dependencies]
|
|
22
18
|
pyo3-build-config = "0.29"
|