perf: offload per-NIO ubridge commands to thread-pool executor

Replace the 3-5 sequential await _ubridge_send calls in _connect_nio
with a single run_in_executor batch.  The batch holds the node-level
asyncio Lock to prevent interleaving with async sends, then uses the
hypervisor's new send_batch_sync method which does blocking socket
sendall/recv inside the thread pool.  Different nodes' batches now
run in true OS-thread parallelism rather than serialising through
the asyncio event loop between every command.

- ubridge_hypervisor.send_batch_sync: blocking batch send using
  the underlying socket from the asyncio transport, protected by
  threading.Lock.
- _connect_nio: builds command list (add_nio_udp, start_capture,
  bridge start, reset_packet_filters, add_packet_filter) and
  dispatches to the default executor.
This commit is contained in:
YueGuobin committed 2026-08-10 23:06:54 +08:00
1 parent 506b0b9f4a
commit 05934fa8e8
3 files changed
+103 -26

No files matched your search

+6 -3
View File
@@ -1440,9 +1440,12 @@ async def test_add_ubridge_connection(vm):
call.send('bridge create bridge0'),
call.send("bridge add_nio_tap bridge0 tap-gns3-e0"),
call.send('docker move_to_ns tap-gns3-e0 42 eth0'),
call.send('bridge add_nio_udp bridge0 4242 127.0.0.1 4343'),
call.send('bridge start_capture bridge0 "/tmp/capture.pcap"'),
call.send('bridge start bridge0')
call.send_batch_sync([
'bridge add_nio_udp bridge0 4242 127.0.0.1 4343',
'bridge start_capture bridge0 "/tmp/capture.pcap"',
'bridge start bridge0',
'bridge reset_packet_filters bridge0',
]),
]
assert 'bridge0' in vm._bridges
# We need to check any_order otherwise mock is confused by asyncio