Improve async reading from socket#47229
Conversation
76b795d to
3fae85f
Compare
f30202c to
9596c21
Compare
|
|
||
| receive_timeout_usec = timeout.totalMicroseconds(); | ||
| connection_fd_description = fd_description; | ||
| epoll.add(connection_fd, events); |
There was a problem hiding this comment.
there is some intersection with the code in ConnectionEstablisher. maybe it could be moved into the base class
There was a problem hiding this comment.
Yes, there are some intersection, but also lots of differences. I tried to come up with base class, but TBH it looked not better than now and I decided not to do it.
azat
left a comment
There was a problem hiding this comment.
Great, plus now the code has less atomics, and some abstractions!
Also maybe it worth to write some test? Introduce another setting like sleep_before_receiving_query_ms (now there is only sleep_after_receiving_query_ms), write huge enough query that is larger the socket buffer and see how long it will take without this patches it should take sleep_before_receiving_query_ms*shards while with only sleep_before_receiving_query_ms
| { | ||
| checkTimeout(/* blocking= */ true); | ||
| to_destroy = std::move(to_destroy).resume(); | ||
| resumeUnlocked(); |
There was a problem hiding this comment.
Now this code works with existing fiber, while previously it had been detached first, though it should not be an issue I guess?
There was a problem hiding this comment.
It's ok. We call cancelBefore under fiber_lock mutex in AsyncTaskExecutor.
Co-authored-by: Azat Khuzhin <[email protected]>
Co-authored-by: Nikita Taranov <[email protected]>
Co-authored-by: Nikita Taranov <[email protected]>
Sure, I will try to do it. |
|
@nickitat sorry for long response to comments, I was distracted by other tasks. Can you continue reviewing please? |
|
Some small testing: First, with Already can see some improvement. Now with As we can see, now we defenitey send query/tmp tables async across shards :) Now, test that we connect to replicas async across replicas and shards: 10 seconds. We spend 5 seconds trying to connect to replica on each shard and don't change replica during it. Now: With I will add some integration tests, but they won't rely on query execution time (it can lead to flakiness), I will use some profile events instead |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Add async connection to socket and async writing to socket. Make creating connections and sending query/external tables async across shards. Refactor code with fibers. Closes #46931. We will be able to increase
connect_timeout_with_failover_msby default after this PR (#5188)CC: @KochetovNicolai, @azat