Commit 7073be1
authored
perf(storage): implement fast-path for queue delivery in _StreamMultiplexer (#16718)
## Summary
This PR optimizes the message delivery logic in `_StreamMultiplexer` to
reduce latency and event loop overhead.
### Performance Improvements:
1. **Fast-path Delivery**: Implemented a "fast-path" that attempts
`queue.put_nowait(item)` for all target queues. For queues with
available capacity, this is a synchronous operation that avoids:
- Creating and scheduling a coroutine.
- Yielding to the event loop.
- Overhead associated with `asyncio.wait_for`.
2. **Single-Queue Slow-path Optimization**: In cases where exactly one
queue is full, the multiplexer now directly awaits the
`_put_with_timeout` coroutine. This bypasses the overhead of
`asyncio.gather`, which is now only used when multiple queues are full
simultaneously.
3. **Reduced Event Loop Pressure**: By minimizing the number of tasks
created and yields performed during high-throughput streaming, these
changes help the multiplexer keep up with fast-arriving gRPC responses.1 parent c6461a4 commit 7073be1Copy full SHA for 7073be1
1 file changed
+34-19Lines changed: 34 additions & 19 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- packages/google-cloud-storage/google/cloud/storage/asyncio
Expand file treeCollapse file tree
Open diff view settings
Collapse file
packages/google-cloud-storage/google/cloud/storage/asyncio/_stream_multiplexer.py
Copy file name to clipboardExpand all lines: packages/google-cloud-storage/google/cloud/storage/asyncio/_stream_multiplexer.py+34-19Lines changed: 34 additions & 19 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
88 | 88 | |
89 | 89 | |
90 | 90 | |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
91 | 96 | |
92 | 97 | |
93 | 98 | |
| ||
100 | 105 | |
101 | 106 | |
102 | 107 | |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + |
103 | 134 | |
104 | 135 | |
105 | 136 | |
| ||
124 | 155 | |
125 | 156 | |
126 | 157 | |
127 | | - |
128 | | - |
129 | | - |
130 | | - |
131 | | - |
132 | | - |
133 | | - |
| 158 | + |
134 | 159 | |
135 | 160 | |
136 | 161 | |
| ||
144 | 169 | |
145 | 170 | |
146 | 171 | |
147 | | - |
148 | | - |
149 | | - |
150 | | - |
151 | | - |
152 | | - |
| 172 | + |
153 | 173 | |
154 | | - |
155 | | - |
156 | | - |
157 | | - |
158 | | - |
159 | | - |
| 174 | + |
160 | 175 | |
161 | 176 | |
162 | 177 | |
|
0 commit comments