Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Channels 2.x or Ajax?

I have a jQuery dataTable, with lots of data(10000+ rows), which can be used/updated in the real time from lots of users and I need that table to be refreshed and up to date all the time. I've tried with Ajax calls on 1 second, and I figured that that's not good, since every user is sending Ajax request every second * 50 or more users, and I think that there must be a better solution. I've been thinking to use Django Channels, or something similar(?) and i was wondering is that possible? Basically I need to set up some kind of listener on the model(database), and to pull the new data on change(that is almost every second). I would love to here an opinion from someone who has more experience than I do. Thank you in advance.

Ps. I've been told to use web sockets for that.

like image 547
dev.ink Avatar asked Oct 28 '25 16:10

dev.ink


1 Answers

In short yes web socket would be the suggested way to do this.

If all the updates to the models that you need to subscribe to are being made through Djangos ORM.

I would suggest looking into using (or be inspired by) DjangoChannelsRestFramework as a starting point for subscribing to multiple models in your db.

This library is set up to let you subscribe to multiple object types over a single web socket connection and get ws messages whenever they objects change. It also provides some tools to let you re-use your existing DRF views over the web socket.

Disclaimer: I am the author of the DjangoChannelsRestFramework.

like image 76
Matthaus Woolard Avatar answered Oct 30 '25 07:10

Matthaus Woolard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!