Geo & capped collections with MongoDB

3,053 views
2,952 views

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,053
On SlideShare
0
From Embeds
0
Number of Embeds
504
Actions
Shares
0
Downloads
16
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Geo & capped collections with MongoDB

    1. 1. Geo & capped collections with MongoDB: Use cases & performance in the real world
    2. 2. /usr/bin/whoami Russell Smith Consultant for UKD1 Limited Specialising in helping companies going through rapid growth Help with code, architecture, infrastructure, devops, sysops, capacity planning, etc <3 gearman, mongodb, neo4j, mysql, kohana, riaksearch, php, debian
    3. 3. What are capped collections? Special option for collections which allow you to; Limit the size of a collection Limit the number of documents in a collection
    4. 4. Why is this useful? Logging News feeds Caching
    5. 5. Restrictions Can’t delete objects (you can drop the collection though) Can’t update objects (well...not 100% true - you can only if the size doesn’t change)
    6. 6. Neat things Objects are returned in the insertion order Don’t have to worry about things growing out of control No more cronjobs to delete old data
    7. 7. Real world example SongFor.com: Activity feeds for the front of the site are using capped collections StrongHold Kingdoms (MMO): Logging of events from syslog / internal events are stored in a capped collection (Graylog2 & a custom dashboard system) Lioness: cache + log of data, used to cut lag & reduce API access requests to Facebook Findlunch.in: Caching of page data
    8. 8. How to setup... db.createCollection("mycoll", {capped:true, size:100000}) db.createCollection("mycoll", {capped:true, size:100000, max:100}); (limit to 100 documents - this is slower as it adds overhead)
    9. 9. What is Geospatial indexing? Allows easily finding things close to a point - great for location based services Insert a document as normal, but with some co-ordinates... ensureIndex({location_field: ‘2d’});
    10. 10. Other magic things You can search $within a $box, or around $center point (circle)...which is handy Results are sorted by distance from points geoNear (command) will return distance, average distance, etc
    11. 11. Versions & support > v1.3.3 for initial version, which is pretty old >= 1.7.0 added spherical support (more in a minute) < 1.7.2 doesn’t support geo in sharded collections. It still has issues see: http://jira.mongodb.org/browse/SERVER-926
    12. 12. and the point is? Really really easy to find documents around a specific point You can get distances from that point as well Lookups are fast and accurate This is a pain to do in MySQL
    13. 13. Example FindLunch.in lets people find lunch close to where they are. Geocode lookup of ~2 million postcodes from the UK All London tube stations & most boroughs are also listed Average query time Xms over 20k of test documents
    14. 14. Questions? Any questions?

    ×