Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 30, 2025

Sequential directory server connections caused slow startup. When connecting to N servers with L ms latency each, startup took N×L ms instead of ~L ms.

Changes

Maker (maker/src/maker/bot.py)

  • Refactored connection loop to asyncio.gather() with return_exceptions=True
  • Extracted connect_to_directory() helper for individual connections

Taker (taker/src/taker/taker.py)

  • Updated MultiDirectoryClient.connect_all() to connect in parallel
  • Extracted connect_to_server() helper for individual connections

Tests (taker/tests/test_parallel_connection.py)

  • Added timing-based validation for parallel execution
  • Added tests for partial failures and exception handling

Orderbook Watcher

  • Already uses asyncio.gather() - no changes needed

Example

Before:

for dir_server in self.config.directory_servers:
    client = DirectoryClient(...)
    await client.connect()  # Blocks until complete

After:

async def connect_to_directory(dir_server: str):
    client = DirectoryClient(...)
    await client.connect()
    return node_id, client

tasks = [connect_to_directory(ds) for ds in self.config.directory_servers]
results = await asyncio.gather(*tasks, return_exceptions=True)  # All in parallel

Performance

Servers Latency Before After Speedup
3 100ms 300ms 100ms 3x
5 100ms 500ms 100ms 5x
Original prompt

This section details on the original issue you should resolve

<issue_title>Connect to all directories simultaneously</issue_title>
<issue_description>At least the maker/taker but maybe also the orderbook watcher should try to connect to all directory servers simultaneously to speed up startup time. Something like an asyncio gather.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Connect to all directories simultaneously during startup Connect to directory servers in parallel using asyncio.gather() Dec 30, 2025
Copilot AI requested a review from m0wer December 30, 2025 11:22
@m0wer m0wer closed this Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connect to all directories simultaneously

2 participants