简体   繁体   中英

Efficient way of updating real time location using django-channels/websocket

I am working on Real Time based app, it needs to update location of user whenever it is changed.

Android app is used as frontend, which get location using Google/Fused Api and in onLocationChanged(loc:Location) , I am sending the latest location over the Websocket . The location update is then received by a django channel consumer , and job of this consumer is to store location in database asynchronously (I am using @database_sync_to_async decorator.

But the problem is, server crashes when Android app tries to send 10-15 location updates per second. What will be the efficient way of updating real time location?

Note: Code can be supplied on demand

Ask yourself what kind of resolution you need for that data. Do you really need 10 updates a second? If not, take every nth update or see if Android will just give you the updates slower. Secondly, look for a native async database library. @database_sync_to_async runs a different thread every time you call it which kills the performance gains you're getting from the event loop. If you say in one thread you'll keep the CPU caches fresh. You won't get to use the ORM. But do you really need a database or would Redis work? If so, call aioredis directly and it will be a lot faster since its in memory and you can use it's fast data structures like queues and sets. If you need Redis to be even faster look at it's multithreaded fork KeyDB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM