pull/39/head
Ciro 2022-11-08 10:07:18 -03:00
rodzic 2e4479cf73
commit a1134dc914
6 zmienionych plików z 153 dodań i 2 usunięć

107
README.md
Wyświetl plik

@ -27,6 +27,113 @@ This project aims to bring high performance PyPy3 web development and will bring
We created and adapt the full C API from [uNetworking/uWebSockets](https://github.com/uNetworking/uWebSockets) and integrate libuv powered fetch and file IO, this same C API is used by [Bun](https://bun.sh/)
<style>
.graph-label{
--black: #0b0a08;
--blue: #00a6e1;
--orange: #f89b4b;
--orange-light: #d4d3d2;
--monospace-font: "Fira Code", "Hack", "Source Code Pro", "SF Mono",
"Inconsolata", monospace;
--dark-border: rgba(200, 200, 25, 0.2);
--max-width: 1152px;
--system-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
sans-serif;
--horizontal-padding: 3rem;
--vertical-padding: 4rem;
--line-height: 1.4;
list-style-type: none;
--count: 3;
--primary: 70px;
--opposite: 100%;
box-sizing: border-box;
--level: calc(var(--amount) / var(--max));
--inverse: calc(1 / var(--level));
color: #fff;
font-variant-numeric: tabular-nums;
font-family: var(--monospace-font);
width: 100%;
text-align: center;
position: relative;
display: flex;
justify-content: center;
top: -22px;
}
.label-bottom{
top: unset;
color: gray;
bottom: calc(calc(200px * var(--level) * -1) + 20px);
}
.graph-bar{
--black: #0b0a08;
--blue: #00a6e1;
--orange: #f89b4b;
--orange-light: #d4d3d2;
--monospace-font: "Fira Code", "Hack", "Source Code Pro", "SF Mono",
"Inconsolata", monospace;
--dark-border: rgba(200, 200, 25, 0.2);
--max-width: 1152px;
--system-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
sans-serif;
--horizontal-padding: 3rem;
--vertical-padding: 4rem;
--line-height: 1.4;
color: #fbf0df;
list-style-type: none;
font-variant-numeric: tabular-nums;
font-family: var(--monospace-font);
--count: 3;
--level: calc(var(--amount) / var(--max));
--inverse: calc(1 / var(--level));
box-sizing: border-box;
--primary: 70px;
--opposite: 100%;
margin: 0 auto;
width: var(--primary);
position: relative;
height: calc(200px * var(--level));
background-color: #5d5986;
}
.socketify{
background-color: gray;
box-shadow: inset 1px 1px 3px #ccc6bb;
background-image: url(https://raw.githubusercontent.com/cirospaciari/socketify.py/main/misc/logo.png);
background-repeat: no-repeat;
background-size: 56px 48.8px;
background-position: 6px 20%;
}
</style>
## Benchmark
HTTP requests per second (Linux x64)
<div style="width: 100%;">
<div align="center" style="width: auto;background-color: #0a0800; border-radius:10px; display: inline-grid;grid-template-columns: 100px 100px 100px 100px; align-items: end;padding: 50px 30px;">
<div style="--amount: 124943; --max: 150000" class="socketify graph-bar">
<div class="graph-label">124,943</div>
<div class="graph-label label-bottom">socketify PyPy3</div>
</div>
<div style="--amount: 70877; --max: 150000" class="socketify graph-bar">
<div class="graph-label">70,877</div>
<div class="graph-label label-bottom">socketify Python3</div>
</div>
<div style="--amount: 30173; --max: 150000" class="graph-bar">
<div class="graph-label">30,173</div>
<div class="graph-label label-bottom">gunicorn Python3</div>
</div>
<div style="--amount: 17580; --max: 150000" class="graph-bar">
<div class="graph-label">17,580</div>
<div class="graph-label label-bottom">gunicorn PyPy3</div>
</div>
</div>
</div>
<br/>
Runtime versions: PyPy3 7.3.9 and Python 3.10.7<br/>
Framework versions: gunicorn 20.1.0 + uvicorn 0.19.0, socketify alpha<br/>
Tested with ./http_load_test 40 127.0.0.1 8000 from [uSockets](https://github.com/uNetworking/uSockets)
Source code in [bench](https://github.com/cirospaciari/socketify.py/tree/main/bench)
## Install
For macOS x64 & Silicon, Linux x64, Windows

Wyświetl plik

@ -0,0 +1,14 @@
import logging
logging.basicConfig()
logging.getLogger().setLevel(logging.CRITICAL)
from flask import Flask
from waitress import serve
app = Flask(__name__)
@app.route('/')
def index():
return "Hello, World!"
serve(app, host='0.0.0.0', port=8000)

Wyświetl plik

@ -0,0 +1,13 @@
from socketify import App
app = App()
app.get("/", lambda res, req: res.end("Hello World!"))
app.listen(8000, lambda config: print("Listening on port http://localhost:%d now\n" % config.port))
app.run()
# 124943.00 req/s socketify.py - PyPy3 7.3.9
# 70877.75 req/s socketify.py - Python 3.10.7
# 30173.75 req/s gunicorn 20.1.0 + uvicorn 0.19.0 - Python 3.10.7
# 17580.25 req/s gunicorn 20.1.0 + uvicorn 0.19.0 - PyPy3 7.3.9
# 8044.50 req/s flask 2.1.2 PyPy 7.3.9
# 1957.50 req/s flask 2.1.2 Python 3.10.7

Wyświetl plik

@ -0,0 +1,17 @@
async def app(scope, receive, send):
assert scope['type'] == 'http'
await send({
'type': 'http.response.start',
'status': 200,
'headers': [
[b'content-type', b'text/plain'],
],
})
await send({
'type': 'http.response.body',
'body': b'Hello, world!',
})
#python3 -m gunicorn uvicorn_guvicorn_plaintext:app -w 1 -k uvicorn.workers.UvicornWorker
#pypy3 -m gunicorn uvicorn_guvicorn_plaintext:app -w 1 -k uvicorn.workers.UvicornWorker

Wyświetl plik

@ -1,6 +1,6 @@
from socketify import App
app = App()
app.get("/", lambda res, req: res.end("Hello World socketify from Python!"))
app.get("/", lambda res, req: res.end("Hello World!"))
app.listen(3000, lambda config: print("Listening on port http://localhost:%d now\n" % config.port))
app.run()

Wyświetl plik

@ -19,6 +19,6 @@ app.ws("/*", {
'drain': lambda ws: print('WebSocket backpressure: %s', ws.get_buffered_amount()),
'close': lambda ws, code, message: print('WebSocket closed')
})
app.any("/", lambda res,req: res.end("Nothing to see here!"))
app.any("/", lambda res,req: res.end("Nothing to see here!'"))
app.listen(3000, lambda config: print("Listening on port http://localhost:%d now\n" % (config.port)))
app.run()