4 ms·
With asynchronous (go-like) channels becoming so popular, I'd love to see some non-blocking Django ORM database calling features. That way, you could fire off a
by beambot 13y ago
With asynchronous (go-like) channels becoming so popular, I'd love to see some non-blocking Django ORM database calling features. That way, you could fire off a few non-blocking db requests and keep executing on the app server (eg. rendering?) until you hit a point where you needed the database data.
I know you could roll your own implementation... but building this into the ORM would still be really slick.
- mattrobenolt 13y agoThere are frameworks that work like this, iirc. I think some in Scala, but I'm not sure. IMO, the added complexity wouldn't be worth it with things like Varnish. I think there are better solutions and this is attacking the wrong problem. But, YRMV. It depends on the situation at hand always.
- yummyfajitas 13y agoBasically anything living in the akka+spray world is written this way. But akka+spray is not an framework in the same sense that django is.
- lmm 13y agoAre there async drivers for e.g. mysql yet? Last time I did that I had a very nice async spray frontend, but it was all backed by a pool of regular blocking threads because that was the only way to use the database driver.
- yummyfajitas 13y agoThere is this, but it's not particularly mature: https://github.com/mauricio/postgresql-async https://github.com/mauricio/postgresql-async I also use https://github.com/etaty/rediscala https://github.com/etaty/rediscala for accessing redis. But even without async drivers for MySQL, you can still do: val sqlResult: Future[StuffFromSql] = future { val stmt = connection.createStatement("...") ... } This will tie up a thread, but you can still run other actions in parallel with it.
- saryant 13y agoIf you do this, execute the future on a different dispatcher so you aren't blocking the default dispatcher. This can cause problems if you tie up the default dispatcher with blocking SQL queries while using clustering: the cluster gossip won't be able to fire and if your failure detection settings are low, that node can be marked unreachable by the rest of the cluster.
- nostrademons 13y agoAppEngine NDB does this for their datastore. Even works with Django, though not with the ORM (you have to use AppEngine's datastore API).