machinalis / telegraphy

Telegraphy provides real time events for WSGI Python applications
202 stars 15 forks source link

Deploying telegraphy #14

Open Brandl opened 10 years ago

Brandl commented 10 years ago

I'm not a Twisted expert and unfortunately I haven't found any explanation in the docs on which is the best setup to use telegraphy in production?

Your recommendation would really help me out.

Kind regards

D3f0 commented 10 years ago

Sorry for the late answer. Telegraphy, in its current state, must run in a different process than gunicorn/uWSGI, or whatever wsgi server your're using. The process is started as a django management process. You must keep this process alive with some sort of process monitor (ie: superivosrd). Although is written on top of twisted, it does not use twisted's twistd.

Fornt end configuration could be done with something like http://nginx.org/en/docs/http/websocket.html.

Brandl commented 10 years ago

Thanks. We decided to run the telegraphy management command with supervisord, so this was a lucky guess. :)

But I've got another question: It's best practice to run websockets on port 80 to avoid getting blocked by a firewall. Which makes this kinda tricky, because (I hope I don't get this wrong) the telegraphy websocket locations have no particular prefix (for the nginx location)? Another possibility to a prefixe would be a ws.example.com subdomain.

Which would be the simplest setup to run telegraphy behind nginx on port 80?


If anyone comes across the same question, this is our supervisord config file:

$ cat /etc/supervisor/conf.d/telegraphy.conf 

[program:run_telegraphy] 
command=/webapps/[app]/bin/python /webapps/[app]/Django/manage.py run_telegraph 
directory=/webapps/[app]/Django
environment=PYTHONPATH='/webapps/[app]/Django' 
user=[restricted_user]
numprocs=1 
stdout_logfile=/webapps/[app]/logs/telegraphy.log 
stderr_logfile=/webapps/[app]/logs/telegraphy.log 
autostart=true 
autorestart=true 
startsecs=10 
stopwaitsecs=30
D3f0 commented 10 years ago

@Brandl indeed, one of the this I have to change is to add a Prefix for telegraphy's WS entry point URLs.