Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice when using folium on django

I'm building an app with django ,which is going display a map of the top voted items.

I'm not an experienced web developed and i wonder where and when and where should build them map. (this line for example --> )

map_osm.create_map(path='osm.html')

Right now i placed in my views.py, and it's building the map each time a user view it, the question is - wouldn't it create too much overhead computation for the server?

I thought about updating it aslo every x votes,or keep a model that will manage it.

what is the best practice in this kind of situation?

like image 609
Amit be Avatar asked Aug 17 '15 13:08

Amit be


People also ask

What is Folium library in Python?

Folium is a powerful Python library that helps you create several types of Leaflet maps. By default, Folium creates a map in a separate HTML file. Since Folium results are interactive, this library is very useful for dashboard building. You can also create inline Jupyter maps in Folium.


1 Answers

Amit. As for folium and building maps for user, yes it could make hard work for server, when a lot of users want to compute. There are solutions for it:

  1. Caching with Redis or Memcached (Django has batteries for it). At this point you can set cache lifetime ~ few seconds to several hours, if coordinates are the same. Django provides view caching, template caching or others.
  2. Save result of maping to db, so if user computes same coodrinates as yesterday - Django will take result from db and show faster to template.
  3. If nothing passes your requirements - just make django faster, turn off unused middlewares, use gunicorn\uwsgi to run and deploy. Locate to web server more RAM and CPU cores (on deploy).
  4. You can try profiling your project , so you can find where is the most computing part at your project. When you found - make it faster.
like image 196
Oleksiy Avatar answered Sep 30 '22 19:09

Oleksiy