Live data from Hacker News

Writing a chat application in Django 4.2 using async StreamingHttpResponse

valberg.dk

1–10 of 36 posts

Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse

#2
This implementation is probably a little different but we were using long poll in the late 90s and early 2000s. The problem was that you were committing one thread (or worse, one process) to each client. That obviously doesn't scale unless threads are extremely light on RAM and either the OS or the runtime support a large number of them. I remember that a way out was using continuations. Jetty was a Java application server that supported them (random link [1]) One thread -> many connections. I didn't investigate how Django is implementing this now but CPUs and RAM are still CPUs and RAM.

[1] https://stackoverflow.com/questions/10587660/how-does-jetty-...

Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse

#4
All the new asyncIO stuff in Django is awesome, they are doing a phenomenal job retrofitting it all to an inherently sync designed framework.

One thing to note, it's been possible to build these sort of things with Django by using Gevent and Gunicorn for over a decade, and it works well.

In many ways I wish Gevent had been adopted by Python rather than AsyncIO.

Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse

#6
post #3

Just a heads up that currently Django is not cleaning up open PostgreSQL connections when ran in ASGI mode, leading to too many open connections error: https://code.djangoproject.com/ticket/33497

that’s kind of a dealbreaker

Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse

#8
post #3

Just a heads up that currently Django is not cleaning up open PostgreSQL connections when ran in ASGI mode, leading to too many open connections error: https://code.djangoproject.com/ticket/33497

that’s kind of a dealbreaker

could this be addressed by something like pgbouncer or another connection pooler?

Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse

#9
post #3

Just a heads up that currently Django is not cleaning up open PostgreSQL connections when ran in ASGI mode, leading to too many open connections error: https://code.djangoproject.com/ticket/33497

I'll have zero trust running async Django until all sync_to_async and async_to_sync calls are removed from the code base.

Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse

#10

Earlier quoted context omitted.

that’s kind of a dealbreaker

could this be addressed by something like pgbouncer or another connection pooler?

Perhaps yes, would be worthwhile to benchmark an internal (to your runtime) conn pooler versus external only.

I'm using internal pools + pgbouncer but as I write this out I am beginning to wonder if that is even necessary.

Post reply on HN