Add silk fibers aware socket implementations#106078
Conversation
|
|
||
| int FiberStreamSocketImpl::receiveBytes(void * buffer, int length, int flags) | ||
| { | ||
| if (flags != 0) |
There was a problem hiding this comment.
Rejecting every non-zero receive flag makes this class incompatible with existing Poco socket callers. ClickHouse HTTP code uses receiveBytes with MSG_DONTWAIT | MSG_PEEK to check whether a peer is still connected, and SecureSocketImpl::receiveBytes forwards exactly that flag combination to the underlying socket before touching SSL. With this implementation that path throws LOGICAL_ERROR, so a fiber socket used there will report the peer as disconnected instead of peeking. Please support at least MSG_DONTWAIT | MSG_PEEK via recv and fiber-aware polling, or explicitly keep these sockets away from code paths that rely on Poco flags.
| int r; | ||
| if (timeout.totalMicroseconds() > 0) | ||
| { | ||
| r = silk::FiberFuture::waitWithTimeout( |
There was a problem hiding this comment.
Poco::Net::StreamSocketImpl::sendBytes preserves nonblocking mode: after callers use setBlocking(false), it attempts one send and returns short progress or EAGAIN so paths such as WriteBufferFromPocoSocket can run their async_callback and enforce the external timeout. This implementation always waits on the fiber future and keeps looping until all bytes are written, so a fiber socket used in those async paths waits here instead of handing control back to the poller. receiveBytes and the secure BIO wrappers have the same contract issue. Please branch on getBlocking/MSG_DONTWAIT and make the nonblocking path return with the same Poco semantics, or reject those async uses before the socket is exposed.
|
@mstetsyuk what's the difference with https://github.com/ClickHouse/silk/blob/main/src/perf/fiber-http.h ? |
|
2 changes on the silk side are required:
|
This PR is basically https://github.com/ClickHouse/silk/blob/main/src/perf/fiber-http.h + TLS + cosmetic changes/simplifications/minor improvements (honouring the receive/send timeout) + tests (I was under the impression that https://github.com/ClickHouse/silk/blob/main/src/perf/fiber-http.h is just for internal perf tests in the silk library - while this PR is meant for normal production usage in our codebase) |
|
This change is required to implement this feature: #106078 |
| @@ -0,0 +1,208 @@ | |||
| #include <IO/SilkFiberStreamSocketImpl.h> | |||
There was a problem hiding this comment.
I would suggest to drop the silk part of a name - just FiberStreamSocket.
I hope there will be just one fiber library in use.
There was a problem hiding this comment.
There is another one, apparently (boost::context).
By the way, what do you think about the Silk namespace? I think it should be useful to gate silk-aware sockets, connection pool, throttlers etc.
| } | ||
| peer.sendBytes("pong", 4); | ||
|
|
||
| std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
There was a problem hiding this comment.
This makes the test timing-dependent: after the server sends pong, if the client fiber is not scheduled until this 100 ms delay has elapsed, x is already queued and the preceding poll can return true. Please use explicit coordination, for example a FiberFuture or latch from the client after the negative poll, before sending x instead of sleeping to order the race.
Apparently, we can make it even simpler. It's the responsibility of the caller to supply the throttler, so I think we can just add And if the user of this class wants to set a throttler, it's on them to use the right one. |
@vadimskipin, addressed by adding a one-liner throttler implementation that does |
|
Unit tests failure should be fixed by: #106856 |
|
Hi @mstetsyuk @nikitamikhaylov @vadimskipin — a couple of suggestions to make this PR easier for reviewers and the changelog reader. Description (currently
Ignore this if the current title/body is intentional. |

Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add silk fiber aware secure and plain socket implementations.
Version info
26.6.1.814