--
You received this message because you are subscribed to the Google Groups "PyWeb-IL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyweb-il+u...@googlegroups.com.
To post to this group, send email to pywe...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyweb-il.
For more options, visit https://groups.google.com/groups/opt_out.
--
Hi!
אני מקוה שאני לא חופר (טלדר), אבל הנה כמה תובנות וקישורים:
Moving from classical web site/app to real time web usually requires considering at least some design changes, even before going to implementation details.
For example: if your user opens his browser, get some info and notification, and later goes offline (leaves the office with his laptop) and then gets back online, what would you like the app to do? Some solutions might be: show all missed notifications (chat:IM style), ignore missed notifications (chat:IRC chatroom style), require a refresh of the page (price ticker?), inform the user and request the user to reload (bank account), or a combination of all the above. This question has to be answered before going forward with implementation.
There are also many types of notification flows: for example, in a chat room or a price ticker, a single message can be generated by the server, and later published to many subscribers, allowing to leverage simple, (and even standard) pubsub mechanisms outside the web server itself. Personal updates, as in email clients probably won't be able to benefit from this, and will still require each message to be generated by the server itself.
When getting closer to implementation details, more thought should be put in dividing the work between the server and the client. Obvious possibilities will be generating all at the server, while sending rendered html to very light and simple JS client. A more modern approach will move all rendering to the client, and send data as JSON. This may include showing an empty page at load, and pumping all data through the socket on connection (see sails.js for example). Intermediate solutions also exist :-)
Once you figured out what you want to do, here are some solutions:
To get thingss working very quickly, you can start with pubnub: https://github.com/pubnub/python/tree/master/python
Subscribe from js, and publish from python. This scales very good, and requires extremely minimal changes to your code, and no infrastructure change at all, but costs $$$$.
If you want to some some bucks, you can implement a pubsub service yourself. From now on you will need to introduce two new technologies to your stack:
- A non-blocking async webserver. Tornado is the usual suspect.
- A shared memory or messaging queue to allow different tornado instances to communicate between them, allowing load (clients) to be shared among more than one process/pc. SQL is (probably) not good enough, as it does not allow subscribing to events on data change. The standard for this service is redis.
Here is a simple, concise yet full tutorial and example for a pubsub service, that can even be used on Heroku, implemented with flask and flask-sockets:
https://devcenter.heroku.com/articles/python-websockets
If you want to go further down the road, and use sockets with your django code, you would probably need to get read from WSGI. However, you can to this only to your websockets: you can write a small tornado app and import your django code from it. You can use nginx routing to divert your websocket urls to your tornado app, or if possible, serve it from a different host/vhost/port.
The following article surfaces lately, allowing to reroute your django views via tornado, but I haven't tested it yet, and it seems like it might be an overkill:
https://github.com/GetBlimp/django-websocket-request
Blog post: http://jpadilla.com/post/74391616727/the-easiest-way-to-add-websockets-to-django
HN Discussion: https://news.ycombinator.com/item?id=7130498
Good luck!
Udi
--
--
--
Cheers
--
You received this message because you are subscribed to the Google Groups "PyWeb-IL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyweb-il+u...@googlegroups.com.
To post to this group, send email to pywe...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyweb-il.
For more options, visit https://groups.google.com/groups/opt_out.