4 ms·
Looks like it has a dependency on Redis and its pub-sub? My speculation: I didn't dig much into code but if Swampdragon relies on Redis pub-sub to notice when
by imslavko 12y ago
Looks like it has a dependency on Redis and its pub-sub?
My speculation:
I didn't dig much into code but if Swampdragon relies on Redis pub-sub to notice when a result of a query might change and then refetches the query and diffs the result (this is a common strategy I saw among different "real-time" web-frameworks), then depending on the complexity of queries and rate of changes you can put the load on your database. And depending on the fetched result, you can spend more CPU cycles on diffing the results.
- andor 12y agoEdit: Swampdragon runs in a Tornado IO loop for real time functionality, and uses Redis Pub/Sub for actual Pub/Sub messaging. It's more like Django bolted to Tornado than Pub/Sub added to Django. * Objects are diffed in the python process before saving the new state. They are diffed with what was loaded from the DB at object initialization time. https://github.com/jonashagstedt/swampdragon/blob/master/swampdragon/models.py#L12 https://github.com/jonashagstedt/swampdragon/blob/master/swa... * Then, the whole object is stored, and the changes are broadcasted. Since the whole object is stored, you can get race conditions if multiple server processes modify it concurrently. https://github.com/jonashagstedt/swampdragon/blob/master/swampdragon/models.py#L66 https://github.com/jonashagstedt/swampdragon/blob/master/swa... * Messages are sent from Python to Redis Pub/Sub channels, and received by Python again. If the Python process has (Websocket) subscribers for the channel, messages are delivered. The indirection over Redis allows having multiple Python processes.
- hagsteel 12y agoIt's not quite accurate to say it's like Django bolted to Tornado. Tornado deals with the websockets, but everything else is Django. You could easily add this to an existing Django project. It's also using Django settings, etc. You are right about the potential race conditions using the self publishing model, but you don't have to use the self publishing model though, it works just as well using the routers + serializers.