Evgeniy Karelin. Mongo DB integration example solving performance and high load problems. DrupalCamp...
-
Upload
vlad-savitsky -
Category
Technology
-
view
1.337 -
download
1
description
Transcript of Evgeniy Karelin. Mongo DB integration example solving performance and high load problems. DrupalCamp...
MongoDB Integration Example Solving Performance And High
Load Problems
Gold Sponsor ofDrupalCamp Kyiv 2011
Silver Sponsors ofDrupalCamp Kyiv 2011
Freerice v2
Easy questions and categories management Users registration Facebook/Twitter integration Friendship system Groups Detailed game statistics per user/group/total,
rating system, user statuses
Round 1 Questions = Nodes. Data imported.
Categories = Nodes + Taxonomy
User profiles = Content profile module
Groups = Organic groups module
Friendship system = Flag module
Game logic, statistics = custom
Blog, comments… = Core modules
Beta test – OK
Live test - Fail
MySQL is slow
Views
node_load()
user_load()
Organic group
Game data processing
…
= SLOW QUERIES
What can help? Pressflow
Memcache
Varnish + AJAX Block
Game as separate script
MySQL replication
Code optimization
AJAX Blocks
AJAX blocks request -> index.php
New module for managing AJAX blocks
Set of blocks on page with needed bootstrap level
Game as separate script
MySQL is slow
What is MongoDB?
Fast INSERTs
Fast SELECTs
Pretty fast UPDATEs
No JOINs
PHP and MongoDB
PECL extension for MongoDB
Very easy to use
Redundancy of documentation and examples on both MongoDB and PHP.net sites
Code examples
Code example
What is 1 right answer?
10 rice
1 update into user tables
1 update into group tables
1 update into totals tables
1 update in user status tables
…
1.5-4.5 millions right answers per day
statistics.grains collection
Every right answer = 1 insert
Statistics recalculation every night
"uid": 1, "cid": 17555, "gid": 0, "amt": 10, "dat": 1305496800, "lvl": 1
Nodes collections
node.question, node.caterogy collection
hook_nodeapi() for insert, update, delete
Full Question and Category nodes into MongoDB
Questions and Categories SELECTs millions time often than INSERTs/UPDATEs
Nothing changed for site administration
statistics.user_totals collection
Other collections
statistic.group_totals
statistic.totals
statistic.useractivity
Views
Bunch of views used on site
Views produce a lot of SELECTs into MySQL
It is not possible to cache them
It is not possible to replace them
sview module
Sview disadvantages
Hard to support
No page/block view “from a box”, custom code needed
Multilingual support
MySQL data is translated as usual
Nothing to translate from users, groups collections
Questions and Categories nodes are fully saved in MongoDB -> easy to translate
MongoDB replication
Why ReplicaSet
Data redundancy
Automated failover
Distribute read load
Simplify maintenance
Recommended for sharding
How to use ReplicaSet
Freerice today
560k registered users
17k groups
25m page views per day
9.3b rice gained = 1m meals
3 DB servers and 2 Front end servers
If you have any questions
http://www.mongodb.org/ http:/php.net/manual/en/book.mongo.php mail: [email protected]
skype: smart_here