squeaky-pl / japronto

Screaming-fast Python 3.5+ HTTP toolkit integrated with pipelining HTTP server based on uvloop and picohttpparser.
MIT License
8.61k stars 581 forks source link

pipelining and async handlers dont mix #46

Open wku opened 7 years ago

wku commented 7 years ago

I understand that this design does not work under load

I would like to understand why and how to fix it, looked "cpipeline.c", but the answer is not obvious to me

from japronto import Application

def require_auth(func): async def auth_stuff(*args, *kwargs): return await func(args, **kwargs) return auth_stuff

@require_auth async def hello1(request): return request.Response(text='Hello world!')

app = Application() app.router.add_route('/', hello1) app.run()

./test.py" Warning: Host CPU doesnt support SSE 4.2, selecting slower implementationAccepting connections on http://0.0.0.0:8080 python3.5: src/japronto/pipeline/cpipeline.c:178: Pipeline_queue: Assertion `self->queue_end < sizeof(self->queue) / sizeof(self->queue[0])' failed. Worker exited with code -6!

wrk -t 1 -c 100 -d 2 -s ./misc/pipeline.lua http://0.0.0.0:8080/ Running 2s test @ http://0.0.0.0:8080/ 1 threads and 100 connections Thread Stats Avg Stdev Max +/- Stdev Latency 0.00us 0.00us 0.00us -nan% Req/Sec 0.00 0.00 0.00 -nan% 0 requests in 2.01s, 0.00B read Socket errors: connect 0, read 110, write 99186, timeout 0 Requests/sec: 0.00 Transfer/sec: 0.00B

wrk -t 1 -c 100 -d 2 http://0.0.0.0:8080/Running 2s test @ http://0.0.0.0:8080/ 1 threads and 100 connections Thread Stats Avg Stdev Max +/- Stdev Latency 2.20ms 451.31us 6.66ms 66.47% Req/Sec 43.66k 1.05k 45.14k 85.00% 86844 requests in 2.01s, 7.62MB read Requests/sec: 43285.00 Transfer/sec: 3.80MB

squeaky-pl commented 7 years ago

This is a duplicate of https://github.com/squeaky-pl/japronto/issues/9

Basically to fix this the pipeline queue size should allow growing and shrinking it's backing buffer with malloc. realloc and free.

squeaky-pl commented 7 years ago

https://github.com/squeaky-pl/japronto/blob/master/src/japronto/pipeline/cpipeline.h#L81 here you can see that its hard-coded to 10 tasks

wku commented 7 years ago

I tried to change the size, but the error remained .. Error in `/usr/bin/python3.5': corrupted double-linked list: 0x0000000002700870 ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fd70d4b77e5] /lib/x86_64-linux-gnu/libc.so.6(+0x80477)[0x7fd70d4c0477] /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fd70d4c398c] /home/wku/WKU/work/server/framework/new_server/+++japronto_1mln/_new/japronto-sse-fallback (2)/src/japronto/protocol/cprotocol.cpython-35m-x86_64-linux-gnu.so(+0x6d0b)[0x7fd709823d0b] /usr/bin/python3.5(PyCFunction_Call+0xa4)[0x4e9bf4] /usr/local/lib/python3.5/dist-packages/uvloop/loop.cpython-35m-x86_64-linux-gnu.so(+0x2163f)[0x7fd70a67363f] /usr/local/lib/python3.5/dist-packages/uvloop/loop.cpython-35m-x86_64-linux-gnu.so(+0x71d44)[0x7fd70a6c3d44] /usr/local/lib/python3.5/dist-packages/uvloop/loop.cpython-35m-x86_64-linux-gnu.so(+0xf99ea)[0x7fd70a74b9ea] /usr/local/lib/python3.5/dist-packages/uvloop/loop.cpython-35m-x86_64-linux-gnu.so(+0x71d8e)[0x7fd70a6c3d8e] /usr/local/lib/python3.5/dist-packages/uvloop/loop.cpython-35m-x86_64-linux-gnu.so(+0xa6a7e)[0x7fd70a6f8a7e] /usr/local/lib/python3.5/dist-packages/uvloop/loop.cpython-35m-x86_64-linux-gnu.so(uv__run_idle+0x84)[0x7fd70a774ab4] /usr/local/lib/python3.5/dist-packages/uvloop/loop.cpython-35m-x86_64-linux-gnu.so(uv_run+0x2d0)[0x7fd70a772b30] /usr/local/lib/python3.5/dist-packages/uvloop/loop.cpython-35m-x86_64-linux-gnu.so(+0x4b250)[0x7fd70a69d250] /usr/local/lib/python3.5/dist-packages/uvloop/loop.cpython-35m-x86_64-linux-gnu.so(+0x9c7f3)[0x7fd70a6ee7f3] /usr/local/lib/python3.5/dist-packages/uvloop/loop.cpython-35m-x86_64-linux-gnu.so(+0x80e5a)[0x7fd70a6d2e5a] .........................