Add usage example to README

This commit is contained in:
James Roberts
2021-10-21 23:21:16 +02:00
parent f4bceae6a8
commit f2f64a8132
6 changed files with 47 additions and 22 deletions

View File

@@ -2,18 +2,36 @@
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/jamesroberts/fast-wsgi.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/jamesroberts/fast-wsgi/context:python)
# Fast WSGI
#### Note: Fast WSGI is still under development...
Fast WSGI is an ultra fast WSGI server for Python 3.
It is mostly written in C. It makes use of [libuv](https://github.com/libuv/libuv) and [llhttp](https://github.com/nodejs/llhttp) under the hood for blazing fast performance.
** Fast WSGI is still under development...
## Example usage with Flask
```python
import fast_wsgi
from flask import Flask
app = Flask(__name__)
@app.get("/")
def hello_world():
return "Hello, World!", 200
if __name__ == "__main__":
fast_wsgi.run(wsgi_app=app, host="0.0.0.0", port=5000)
```
## TODO
- Memory lifecycle management
- Python object ref count tracking
- WSGI app invoking
- Test integration with flask app
- Basic error handling
- Test integration with other frameworks (uWSGI, Django, etc)
- Comprehensive error handling
- Complete HTTP/1.1 compliance
- Test on multiple platforms (Windows/MacOS)
- Unit Tests

View File

@@ -225,8 +225,8 @@ void build_response(PyObject* wsgi_response, StartResponse* response, llhttp_t*
PyObject* close_result = PyObject_CallObject(close, NULL);
Py_XDECREF(close_result);
}
Py_DECREF(close);
Py_DECREF(iter);
Py_XDECREF(iter);
Py_XDECREF(close);
Py_XDECREF(result);
result = NULL;
}

View File

@@ -2,7 +2,6 @@ import os
import signal
import _fast_wsgi
from flask import Flask, request
NUM_WORKERS = 4
HOST = "0.0.0.0"
@@ -33,15 +32,8 @@ def run_multi_process_server(app):
os.kill(worker, signal.SIGINT)
app = Flask(__name__)
@app.route("/test", methods=["GET"])
def hello_world():
return {"message": "Hello, World!"}, 200
if __name__ == "__main__":
def run(wsgi_app, host, port, backlog=1024):
print("Starting server...")
enable_logging = 0
_fast_wsgi.run_server(wsgi_app, host, port, backlog, enable_logging)
# run_multi_process_server(app)
_fast_wsgi.run_server(app, HOST, PORT, BACKLOG, 1)

View File

@@ -1 +1 @@
wrk -t8 -c100 -d15 http://localhost:5000/test
wrk -t8 -c100 -d15 http://localhost:5000

2
run.sh
View File

@@ -1 +1 @@
sudo python3 setup.py install; python3 fast_wsgi.py; fuser -k 5000/tcp;
sudo python3 setup.py install; python3 testapp.py; fuser -k 5000/tcp;

15
testapp.py Normal file
View File

@@ -0,0 +1,15 @@
import fast_wsgi
import bjoern
from flask import Flask
app = Flask(__name__)
@app.get("/")
def hello_world():
return "Hello, World!", 200
if __name__ == "__main__":
# fast_wsgi.run(wsgi_app=app, host="0.0.0.0", port=5000)
bjoern.run(app, "0.0.0.0", 5000)