httpx icon indicating copy to clipboard operation
httpx copied to clipboard

Implement asyncstreams

Open termermc opened this issue 2 years ago • 7 comments

Implements:

  • Async streaming I/O when httpxUseStreams is true
  • Exposes request ID
  • Exposes parsed request content length

TODO In another PR:

  • Limit request header sizes to 8kib
  • Write documentation for streams mode

termermc avatar Apr 05 '23 09:04 termermc

Tested with Prologue, it passes as well.

ringabout avatar Apr 09 '23 13:04 ringabout

how's the performance change?

bung87 avatar Jun 15 '23 02:06 bung87

@bung87 Really bad. That's part of why I never finished it. You can checkout the branch and try it for yourself.

termermc avatar Jun 15 '23 02:06 termermc

I've heard of the low performance when nim std provide stream api, because it uses dynamic dispatch functions.

bung87 avatar Jun 15 '23 03:06 bung87

I don't think mine uses dynamic dispatch, but there are problems with how httpx/httpbeast read sockets which makes the problem worse.

You can see my implementation here:

https://github.com/ringabout/httpx/blob/83f6a1a839ba0c322859f876938a8881100df4ec/src/httpx/asyncstream.nim

And its tests:

https://github.com/ringabout/httpx/blob/83f6a1a839ba0c322859f876938a8881100df4ec/tests/t_streams.nim

termermc avatar Jun 15 '23 03:06 termermc

these functions associate with stream object are dynamic dispatch, no ?

result.readCbs = initDeque[AsyncStreamCb](1)
result.writeCbs = initDeque[AsyncStreamCb](1)
result.afterReadCb = afterReadCb
result.afterWriteCb = afterWriteCb

bung87 avatar Jun 15 '23 03:06 bung87

@bung87 AsyncStreamCb just a typedesc, not a method. It won't use dynamic dispatch vtables, but it does run a proc via its pointer. Not sure if that counts.

termermc avatar Jun 15 '23 03:06 termermc

Any progress on this one?

atlas-pouriya avatar Sep 27 '24 08:09 atlas-pouriya

@atlas-pouriya I've abandoned it, the architecture is just too different to support it without breaking everything or making a compiletime switch that requires a lot of conditional code which is hard to test.

I'll close it now.

termermc avatar Sep 28 '24 23:09 termermc