Hi Emil,I also like "server sent events" (EventSource). They get through proxies much more reliably than WebSockets. :)
"You would start the process separately, add a script tag to your page, and all clients that connected to the page would be connected to the process. Now Django could push messages through that process as part of the request-response cycle, and all clients would be notified. Other processes (a cron job?) could do the same."
Have you thought about how to scale this across multiple machines?Thanks,Collin
On Saturday, May 30, 2015 at 12:51:33 PM UTC-4, Emil Stenström wrote:Hi!
A couple of weeks ago I held a presentation on PyCon Sweden 2015 with
the title "Why Django Sucks". The idea was to follow in the footsteps of
great conference talks like these:
https://www.youtube.com/playlist?list=PLGYrvlVoAdf9j3v_teol3s7hl8gkUd8E2
These talks are great because they encourage people to take an outside,
critical, perspective of Django and where it's going.
My talk was well received, with many both interested and skeptical
questions afterwards. Unfortunately, the final video was missing the
sound, so the camera crew is working on fixing that now. I'll post it to
this thread as soon as I get it. Meanwhile, here's a text summary:
---
The theme for my talk was that Django's bad support for Javascript heavy
sites. Everyone is using javascript for their sites nowadays. Problem
is, Django (and large parts if the Django community) has long had a
approach to Javascript that can be summed up with Simon Willison's reply
to someone asking for AJAX support in 2005:
"For me "Ajax support" really is pure marketing fluff - as far as I'm
concerned EVERY web framework supports Ajax unless it does something
truly moronic like refuse to let you output documents that don't have
the standard header/footer template."
Source: http://bit.ly/django2005
The problem with this mindset (I'm not picking at Simon from 10 years
ago) is that the web as large is moving towards MORE javascript, with
live notifications, live updating templates, and reusable template
components. And these are hard to implement in Django as things work
today. I see this is the biggest competitive disadvantage Django has
going forward.
So, what specific features am I proposing? I will get to a specific set
of features soon. But first I want to make clear that a completely
different set of features could get us to the same goal. That is: it's
possible to agree on the broader goal for Django, and disagree on my
specific set of features. If you don't agree on the features, I would
love to see your proposed feature list.
Just to give one alternate path: In that old thread from 2005, Jacob
Kaplan-Moss suggested exposing the ORM through Javascript with an RPC API:
https://groups.google.com/d/msg/django-developers/XmKfVxyuyAU/lkp6N1HTzG4J
Jacobs suggestion is interesting, but I have three other features that I
would like to discuss. I think they would greatly ease building
javascript heavy sites with Django.
*I will split the specific suggestions into three different e-mail
threads, so we can discuss them separately*.
Here's a short intro to them:
1. Template Components
React.js popularized the notion that in front-end development, code
organization should be based on interface components, not split up into
HTML, Javascript and CSS. It's simply a different way to organize the
code for your front-end, that I strongly think Django should make
easier. (read more in separate thread)
2. Support a client side template language
The multiple template engine work has made it possible to switch out
Django Templates with another engine. One of the most powerful things
this enables is to use a template language that is executable both on
the server and client. This means you can do the same kind of live
updates to your page that the Meteor.js people are doing, and just
re-render parts of the DOM as a direct result of a database update.
(read more in separate thread)
3. Support Server-Sent Events
If you want a snappy user experience, polling isn't enough. There are
two major ways to get out of the request-response cycle. Namely:
websockets and server-sent events. Server-Sent Events have a much
simpler protocol, and could be implemented with asyncio (no external
dependencies except for backwards compatibility) in a performant way. It
would be a great reason to choose Django over other frameworks. (read
more in separate thread)
---
This is not a "request for features". I am in no way saying that I think
you should build things for me. Instead I'm willing to work on them
together with anyone interested, if these are features that the core
team would be interested in.
But first I would like to see if you:
1. Agree on the main point that Django should do more for javascript
heavy sites.
2. Agree that one or more of the specific features that I'm proposing
would be a good fit for Django (see separate threads).
No matter what, I would love to hear your thoughts and ideas here.
So the SSE process is VERY simple. It just connects to clients and passes on messages the all clients connected.
Does this make sense?
/E
Also, I don't think you would need to mix redis (or any other persistent storage) into this. The connected clients could simply be stored in an in-memory array, that is discarded if the server crashes. When the server is started again the clients will automatically connect again, and the list of clients would be built up again.
On Sun, May 31, 2015 at 3:52 AM, Emil Stenström <e...@kth.se> wrote:
> Could you help me understand why this have to be done inside a web server
> container?
AFAICT, it doesn't have to be done in the container, but currently it
must be 'outside' of Django. But having help from the container
allows a single request to be passed from one handler (a Django view)
to another (the SSE process). it might be easier if you use an URL
that goes directly to the SSE process and isn't touched by Django, but
then you need some kind of router, or 'outer url dispatcher'. unless
the SSE requests can be at a different port from the start? in that
case, the SSE process will need its own URL dispatcher.
> Also, I don't think you would need to mix redis (or any other persistent
> storage) into this. The connected clients could simply be stored in an
> in-memory array, that is discarded if the server crashes. When the server is
> started again the clients will automatically connect again, and the list of
> clients would be built up again.
in-memory as a Python object? but i think the SSE handler must be a
different interpreter instance... unless it's a thread... not sure if
the GIL would be an issue... or an "external" in-memory table? well,
that's what Redis is.
Client A clicks a button on the site, that sends an normal ajax request to Django. In the view a message is passed from Django to the SSE process.
So the SSE process is VERY simple. It just connects to clients and passes on messages the all clients connected.
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/86b8ff28-b35f-49cd-8e95-30ace07c9d51%40googlegroups.com.
The fact that you keep describing your idea as another process/thread that has back and forth communication with the actual Django instance seems to indicate to me that it's another program.
I think people here tend to follow more of the UNIX philosophy of a collection of smaller simple programs that can easily interact (monolithic stack being ignored as that's a much older decision).
If you want tighter integration with Django, I think it would best be done via your program instead of Django itself.
Keep up the good work.
On Saturday, May 30, 2015 at 10:40:26 PM UTC+1, Emil Stenström wrote:Client A clicks a button on the site, that sends an normal ajax request to Django. In the view a message is passed from Django to the SSE process.
How, you still need some kind of interprocess communication
So the SSE process is VERY simple. It just connects to clients and passes on messages the all clients connected.
VERY simple is an oversimplification in my opinion. I also do not see any reason for supporting it inside Django currently when things like autobahn.ws exist, the only thing missing there is the communication between the processes.
I am not sure what people are expecting here from Django (and from your explanations I am still not really convinced or see a usecase at all).
Since the message passing between the server processes should be language/framework agnostic anyways, this would be better suited for a third party project anyways. Reimplementing one of the existing SSE/Websockets implementations does not really seem like a win to me either.
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d1148851-7ced-4463-9bf5-02a54d5a5ade%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAG_XiSCQRorXF-QKvO6GF6Rq3Lf7M29vqdTdjvcgcYKw%2B5tYZg%40mail.gmail.com.
I think the real questions are:1. What is stopping a 3rd party product from providing the features you want?
2. Why should your solution be the "blessed" solution?
The discussion clearly shows there are several ways to skin this cat... why is your way better than any other? Until there is a clear winner [see migrations and South] it should live as a 3rd party app, with Django providing whatever mechanisms/support it can.Personally, I've used DOM-SSE to implement a simple chat service in Django, using Redis for the PUB-SUB server. It was only really feasible because (a) I used gevent, (b) no ORM means no need for async DB adapter, and (c) the py-redis module is Pure Python, so can be monkey patched.[FYI I've also translated that same code to raw WSGI app, and using async-io, available on github if you're interested </shameless-plug>]
Just to chime in here - I've long been in favour of some kind of support for event-driven stuff inside Django, but as Curtis is saying, there's nothing here that couldn't be done in a third party app first and then proven there before any possible merge into core.
I also don't think that this proposal goes far enough, in a way - any push for a system that allows asychronous calling like this should be available to the request-response cycle as well as websocket/push clients (I want the ability to make my database calls in parallel with my external API calls, perhaps). I have some ideas down this path, but even those are the sort of thing that need a couple of changes to Django to make things work smoothly but the bulk can be implemented outside.
If there's specific things Django needs changed to support this properly, I'm all ears, but I'm not sure we should just lump a certain pattern of socket worker in core straight away.
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/4bbf9e68-b1b8-4701-bca7-eb062626e94b%40googlegroups.com.
Hi Emil,I agree that there perhaps needs to be a more "pull" here than just making a third party app, but I feel I can speak from a good place when I say third party apps can absolutely prove core Django features in a way that gives them much faster release cycles and freedom from things like LTS commitments initially, so they can be rapidly improved upon before being deemed worth merging. The alternative is either merging something into core that's not ready, dooming it to a slow release cycle and perhaps community pushback, or developing it as a parallel branch which is not something that's going to be long-term sustainable.
This problem has been something I've been wanting to tackle for a while now - I've always felt that the next step for Django is to start moving away from being so married to the request-response cycle of traditional HTTP - and I've been formulating a plan over the last few months about how to tackle it. It's relatively ambitious, but I think entirely achievable and would be almost completely backwards-compatible. Unfortunately, it's taken a while to get over the 1.7 release cycle and migrations work being slightly overwhelming, or it would have been sooner.
I'm sounding out some of the ideas here at DjangoCon Europe, and hopefully come to the list with an initial proposal or implementation soon - I think the best way to approach this is to sit down and design the API and core code architecture, start proving it's possible, and then present that, because in my experience having code examples can really make a proposal a lot easier to understand. Of course, I'm also fully prepared for people to shoot down my ideas - being a core team member doesn't give me some magical ability to push through changes.