Created
January 17, 2019 13:44
-
-
Save gcavalcante8808/1f0a89ed72a3b3aca5dc63e2804eb896 to your computer and use it in GitHub Desktop.
Bjoern Django Final
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bjoern | |
import os, signal | |
from django.core.wsgi import get_wsgi_application | |
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings') | |
app = get_wsgi_application() | |
NUM_WORKERS = 8 | |
worker_pids = [] | |
bjoern.listen(app, '0.0.0.0', 8000) | |
for _ in range(NUM_WORKERS): | |
pid = os.fork() | |
if pid > 0: | |
# in master | |
worker_pids.append(pid) | |
elif pid == 0: | |
# in worker | |
try: | |
bjoern.run() | |
except KeyboardInterrupt: | |
pass | |
exit() | |
try: | |
# Wait for the first worker to exit. They should never exit! | |
# Once first is dead, kill the others and exit with error code. | |
pid, xx = os.wait() | |
worker_pids.remove(pid) | |
finally: | |
for pid in worker_pids: | |
os.kill(pid, signal.SIGINT) | |
exit(1) |
@phacic Are u using it in a container?
If you're using it on a container, remember to add a tty: true
to allow the KeyboardInterrupt
to be passed to the script, otherwise use exec wsgi_bjoern.py
as your entrypoint/cmd to maintain the same behavior.
@gcavalcante8808 yes, am using it in a container.
Will give it a try and let you know the results. Thanks
Amazing ))) 17K PRS on M1 laptop using Bjoern and 400RPS with 50% of "connection interrupt" and timeouts with Gunicorn )))
i havent seen this server as option between others (gunic, uwsgi...), has someone used it in production ?
@lyf2000 I have used it 3 years ago with success. I didnt know how it goes in these days since I've been working with java and php lately =(
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ctrl+C
doesn't close the server. The server only closes on container exit. Any help?