HNHacker News
TopNewBestAskShowJobs

cirospaciari

169 karma · joined November 8, 2022

submissionscomments
cirospaciari··on Show HN: Socketify.py: Http/Https and WebSockets servers for PyPy3 and Python3
Django is an WebFramework, Meinheld is an WSGI Server framework.

https://github.com/django/django

https://github.com/mopemope/meinheld

So django meinheld is basically saying that i used Django served by meinheld in that benchmark.

cirospaciari··on Show HN: Socketify.py: Http/Https and WebSockets servers for PyPy3 and Python3
I see, but like i said any performance focused Python framework are native (C/C++), so i will never be able to compare any Python framework with Golang framework ever.
cirospaciari··on Show HN: Socketify.py: Http/Https and WebSockets servers for PyPy3 and Python3
asyncio and python async is very slow, that's why i'm planning to build alternatives to it too!
cirospaciari··on Show HN: Socketify.py: Http/Https and WebSockets servers for PyPy3 and Python3
socketify is based on uWebSockets (C++) uWebSockets is comparad to FastHTTP and socketify adds a lot of features on top.

The benchmarks are TechEmPower plaintext https://github.com/TechEmpower/FrameworkBenchmarks

preliminary results here: https://www.techempower.com/benchmarks/#section=test&runid=1...

cirospaciari··on Show HN: Socketify.py: Http/Https and WebSockets servers for PyPy3 and Python3
Python framework because is an framework for python, like most performance focused frameworks for python, this uses a lot of native code. uvicorn uses uvloop that is an wrapper for libuv.

Web developer dont care if the framework is written in native or it is an wrapper, developers just want something that works in a nice way :D

The benchmarks are in https://github.com/TechEmpower/FrameworkBenchmarks

EDIT: some preliminary results https://www.techempower.com/benchmarks/#section=test&runid=1...

cirospaciari··on Show HN: Socketify.py: Http/Https and WebSockets servers for PyPy3 and Python3
Yeah i have a lot of things to do, to minimize this types of things. But Caching Tools that never cross GIL will boost a lot of performance in real life scenarios too. See https://github.com/cirospaciari/socketify.py/issues/60 I plan to create an native Redis cache and memcache too.
cirospaciari··on Show HN: Socketify.py: Http/Https and WebSockets servers for PyPy3 and Python3
You can see the preliminaries results here

https://www.techempower.com/benchmarks/#section=test&runid=1...

cirospaciari··on Show HN: Socketify.py: Http/Https and WebSockets servers for PyPy3 and Python3
uvicorn uses uvloop that is an wrapper to libuv ;) almost any performance focused package use native extensions (CFFI, Cython, HPy, Python CAPI etc)
cirospaciari··on Show HN: Socketify.py: Http/Https and WebSockets servers for PyPy3 and Python3
uvicorn and fastapi is backed by libuv :) it uses uvloop
cirospaciari··on Show HN: Socketify.py: Http/Https and WebSockets servers for PyPy3 and Python3
Yeah, I'm converting to HPy and it probably will be faster in CPython too, but like you said AOT is hard to beet without JIT at least. But with CPython is faster than Golang Gin :D
cirospaciari··on Show HN: I started the development of the fastest ASGI and WSGI Server
After starting the project called socketify.py at https://github.com/cirospaciari/socketify.py, I got pretty good results and reviews, but many people asked if socketify.py could be used to create a WSGI and ASGI server. WSGI and ASGI have a lot of overhead, that's is why I choose not to use them in the first place, but adding an ASGI and WSGI server allows a lot of code already written to run faster!

The focus of socketify is PyPy not because it allows for more CPU-intensive workloads, but because it also allows removing a lot of overhead of CPython itself!

The performance targets for ASGI with CPython were the same as uvicorn for ASGI and meinheld for WSGI, and I am happy to say that we got it to be faster in most cases and at least on pair in the worst case! Socketify ASGI 541,645 vs uvicorn 337,265 in CPython every single framework got a performance boost in WSGI and/or ASGI.

Falcon is the only one that is a little bit faster in WSGI with meinheld using CPython but socketify WSGI managed to get into the same ballpark of performance.

Using with PyPy we are the fastest ASGI and WSGI in all scenarios with a HUGE margin.

Falcon manage to pass the 1 million requests/s mark, and Flask and Django are faster than ever socketify WSGI,

FastAPI from 165k using uvicorn + gunicorn goes to 423k using socketify ASGI with PyPy

Emmett from 208k using uvicorn + gunicorn goes to 558k using socketify ASGI with PyPy

Falcon is the ASGI champion in throughput with 625k requests/s

cirospaciari··on Show HN: Record breaking performance for Python, 6.2 mi req/s in TechEmPower
It is a package to work with websockets too! and in future raw sockets, fetch like API, async file IO etc, that is why the name is socketify.py

More realistic benchmarks will come soon, keep an watch in the github project ;)

P.S. Vibora is not alive unfortunately last commit was in 2019 and last release branch in 2018 :/ but someone just put Vibora in TechEmPower this year.

cirospaciari··on WebSocket Server in C
Really cool i also made and CAPI for using WebSocket in C, https://github.com/uNetworking/uWebSockets/tree/master/capi

I will take a deep look on your project thanks for sharing!

cirospaciari··on [dead]
It's a really an over simplificated microbenchmark, but shows a big difference between TechEmPower benchmarks using wrk and + 16 pipelining with an lua script, and of course will not hit 1 million req/s on my machine, running tfb tools in my machine socketify.py + PyPy3 hits 770k req/s for some context.

It also show that PyPy3 will not magically boost your performance, you need to integrate in a manner that PyPy3 can optimize and delivery CPU performance, with a more complex example maybe it can help more. But why socketify is so much faster using PyPy3? The answer is CFFI, socketify did not use Cython for integration and cannot delivery the full performance on Python3, this will be solved with HPy.

Also we can see that the Cython + meinheld (that is builded with C) are WAY faster than other options of falcon, but you will not get an optimized JIT for all python code that you write in a real life project.

HTTP pipelining is buggy and not really supported by browsers, the technique was superseded by multiplexing via HTTP/2, which is supported by most modern browsers, TechEmPower don't test HTTP/2 or HTTP/3.

In HTTP/3, multiplexing is accomplished via QUIC which replaces TCP. This further reduces loading time, as there is no head-of-line blocking even if some packets are lost.

Supporting HTTP/2 and HTTP/3 is way more important than winning TechEmPower HTTP/1.1 benchmarks, this only means you need to take any benchmark with a grain of salt, and run bencharks in an more close to reality scenario by our self, Caching strategy, Bandwidth, Latency, CPU time, Memory, all are relevant and not really tested here.

cirospaciari··on Show HN: Socketify.py – Maybe the fastest web framework for Python and PyPy
We got about 770k req/s with the current version vs 582k from japronto using TechEmPower plaintext benchmarks and we still can get at least 30% or more performance once fully integrated with libuv + asyncio :D
← PreviousPage 2 of 2