viola is a lightweight and efficient WSGI server.
Project description
viola
viola is a WSGI server. Lightweight and efficient and has no dependencies other than the Python Standard Library. Usually used with Nginx. I build blog with viola, handle static resource by Nginx and dynamic content with viola. You can also do this or using viola as a reference for learn networking programming.
Table of content:
Features
- Single-thread, non-blocking I/O based on event-driven model
- Simplified WSGI protocol for server side
- Second timer
- A parser for HTTP GET method
Requirements
- Python
- CPython >= 3.6
- Platform
- Linux and kernel >= 2.6
Installation
Package is uploaded on PyPI
You can install with pip:
$ pip install viola
Example
Use viola as follows:
from viola.core.event_loop import EventLoop
from viola.wsgi.server import WSGIServer
from viola.core.scheduler import Scheduler
# Import your APP in here
if __name__ == '__main__':
event_loop = EventLoop.instance(Scheduler.instance())
server = WSGIServer(event_loop)
server.set_wsgi_app(APP) # For example the APP argument is flask or bottle
server.bind(host=HOST, port=PORT) # Replace your real host and real port
server.listen()
server.start(1)
event_loop.start()
That's all.
Performance
The following nginx are proxy with one WSGI server. Nginx configuration is consistent and the WSGI server response a string "Hello World".
CPU: 2.7 GHz Intel Core i5
MEM: 8 GB 1867 MHz DDR3
ab -n 10000 -c 500 http://10.211.55.25/
Nginx + Tornado(Tornado as both a WSGI server and Web framework. Tornado start one process)
$ ab -n 10000 -c 500 http://10.211.55.25/
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 10.211.55.25 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: nginx/1.15.8
Server Hostname: 10.211.55.25
Server Port: 80
Document Path: /
Document Length: 12 bytes
Concurrency Level: 500
Time taken for tests: 31.186 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 2190000 bytes
HTML transferred: 120000 bytes
Requests per second: 320.65 [#/sec] (mean)
Time per request: 1559.316 [ms] (mean)
Time per request: 3.119 [ms] (mean, across all concurrent requests)
Transfer rate: 68.58 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 3.3 0 20
Processing: 13 797 3684.3 121 31161
Waiting: 9 797 3684.3 121 31161
Total: 28 798 3686.2 122 31170
Percentage of the requests served within a certain time (ms)
50% 122
66% 132
75% 141
80% 149
90% 168
95% 1002
98% 15038
99% 15135
100% 31170 (longest request)
Nginx + Gunicorn(workers 4 and use sync mode by default) + bottle
$ ab -n 10000 -c 500 http://10.211.55.25/
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 10.211.55.25 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: nginx/1.15.8
Server Hostname: 10.211.55.25
Server Port: 80
Document Path: /
Document Length: 12 bytes
Concurrency Level: 500
Time taken for tests: 15.113 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1690000 bytes
HTML transferred: 120000 bytes
Requests per second: 661.67 [#/sec] (mean)
Time per request: 755.662 [ms] (mean)
Time per request: 1.511 [ms] (mean, across all concurrent requests)
Transfer rate: 109.20 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 3.0 0 21
Processing: 13 407 1826.5 57 15085
Waiting: 13 407 1826.5 57 15085
Total: 30 408 1827.8 57 15091
Percentage of the requests served within a certain time (ms)
50% 57
66% 62
75% 81
80% 91
90% 120
95% 1063
98% 7065
99% 15056
100% 15091 (longest request)
Nginx + viola(viola start one process) + bottle
$ ab -n 10000 -c 500 http://10.211.55.25/
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 10.211.55.25 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: nginx/1.15.8
Server Hostname: 10.211.55.25
Server Port: 80
Document Path: /
Document Length: 12 bytes
Concurrency Level: 500
Time taken for tests: 3.090 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1290000 bytes
HTML transferred: 120000 bytes
Requests per second: 3236.64 [#/sec] (mean)
Time per request: 154.481 [ms] (mean)
Time per request: 0.309 [ms] (mean, across all concurrent requests)
Transfer rate: 407.74 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 3.0 0 22
Processing: 1 133 532.0 23 3042
Waiting: 1 133 532.0 23 3042
Total: 9 134 533.3 24 3053
Percentage of the requests served within a certain time (ms)
50% 24
66% 28
75% 35
80% 39
90% 50
95% 67
98% 3016
99% 3037
100% 3053 (longest request)
TODO
- Improved WSGI protocol of server side
- Millisecond timer
- HTTP POST method and more
- Improved response module
- Event driven for more platforms
- Improved coverage
Reference
- EPOLL(7)
- How To Use Linux epoll with Python
- Python Standard Library
- An overview of HTTP
- RFC 2616 -- HTTP GET method
- PEP 333
- Tornado
- Gunicorn
License
viola is released under the MIT License. See LICENSE for more information.
Contributing
Thank you for your interest in contribution of viola, your help and contribution is very valuable.
You can submit issue and pull requests, please submit an issue before submitting pull requests ^_^.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file viola-0.3.8.tar.gz
.
File metadata
- Download URL: viola-0.3.8.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2240273dbbbaf729cf868be81834bcee9df6ef11570c39eb30a25c20c9f16c3f |
|
MD5 | 4b96c888155db5d018a00da030f82af2 |
|
BLAKE2b-256 | cec6e4f19e78117358924a1b63478b67515d9e6db6e3d6fa7a7fb936a9dd16a4 |
File details
Details for the file viola-0.3.8-py3-none-any.whl
.
File metadata
- Download URL: viola-0.3.8-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6875b1ded7433871979bf2b691a98fa039c8910a7ae75b239515087bbc0c8bd1 |
|
MD5 | 6eb9b99933c607d45913b047e0a611de |
|
BLAKE2b-256 | 761362a5785eddb80789c7057f82f2a5af569b230e37f81dbb7a794aa887a74a |