大è¦æ¨¡ç°å¢ã§ãã¹ã±ã¼ã©ããªãã£ãåé·æ§ã確ä¿ããMongoDB
ããã°ã©ã¤ãã¯ã¢ã¡ã¼ããã°ã®ãµã¼ãã¹å ã²ã¼ã ã§ããããã¾ã£ããå¥ã®ã·ã¹ãã ã§åä½ãã¦ãããã¢ã¼ããã¯ãã£ãã¾ã£ããç°ãªããã¢ã¡ã¼ããã°ãJavaï¼MySQLã¨ããå¾æ¥åã®Webã¢ããªã±ã¼ã·ã§ã³ã§ããã®ã«å¯¾ãããã°ã©ã¤ãã¯ã¢ããªã±ã¼ã·ã§ã³ãµã¼ããNode.jsããã¼ã¿ãã¼ã¹ãµã¼ãã«ã¯MongoDBãæ¡ç¨ãã¦ããã
ãMongoDBã¯ããªã¼ãã³ã½ã¼ã¹ã®ããã¥ã¡ã³ãæåãã¼ã¿ãã¼ã¹ã§ãç±³10gen社ã«ãã£ã¦éçºã»æä¾ããã¦ãããããããNoSQLã®ä¸ç¨®ã ããKVSã»ã©åç´ã§ã¯ãªããJSONããã¼ã¹ã¨ãããBSONï¼ãã¤ããªJSONï¼ãã«ããã¹ãã¼ãã¬ã¹ã§æè»ãªãã¼ã¿ã¢ãã«ã§ãããã¨ãç¹é·ã ã
ãæ¬ã»ãã·ã§ã³ã®ååã§ã¯ããã°ã©ã¤ãã§MongoDBãæ¡ç¨ããçç±ã¨ãã®éç¨ææã«ã¤ãã¦æ¡éç« å¼æ°ãçºè¡¨ããããã®çç±ã¨ãã¦ã¯ã次ã®ãããªã¢ã¼ããã¯ãã£ã®èª²é¡ã解決ããããã ã¨ããã
- éçºã¹ãã¼ã
- ãµã¼ãã¹ã¢ã¼ããã¯ãã£ã®èª²é¡
- ã·ã¹ãã ã¢ã¼ããã¯ãã£ã®èª²é¡
- åé·å
- ã¹ã±ã¼ã©ããªãã£
ãéçºã¹ãã¼ãã®é¢ã§æ¡éæ°ãã¾ãæããã®ã¯ãNode.jsã¨ã®ç¸æ§ã®è¯ãã§ããããã¼ã¿ã¢ãã«ãJSONãã¼ã¹ã§çµ±ä¸ãããããã·ãªã¢ã©ã¤ãºãä¸è¦ã«ãªããã¾ãããã¼ã¿ç®¡çãæè»ã«è¡ãããããæ©è½è¿½å æã«SQLãµã¼ããªãã«ã©ã 追å ãå¿ è¦ã«ãªãã¨ããããã¹ãã¼ãã«ãªãã¸ã§ã¯ãã追å ãã¦ãããã¨ã§ãæ°ããæ©è½ã«å¿ è¦ãªãã¼ã¿ã»ãããããã«è¿½å ã§ããã
ãã¾ãããã¼ã¿ãã¼ã¹ãµã¼ãã¼ã«ã¤ããã®ã®èª²é¡ã§ããåé·åã¨ã¹ã±ã¼ã©ããªãã£ã«é¢ãã¦ã¯ãããããShardingï¼ã·ã£ã¼ãã£ã³ã°ï¼ã¨ReplicaSetsï¼ã¬ããªã«ã»ããï¼ã¨ããæ©è½ã«ãã£ã¦è§£æ±ºã§ããã
ãShardingã¯ãã¼ã¿åæ£ã®ä»çµã¿ã§ããã¼ã¿ãèªåã§Chunkï¼ãã£ã³ã¯ï¼ã«åå²ããè¤æ°ã®mongodã«åæ£ãã¦é ç½®ãã¦ããããããã«ãã£ã¦ãµã¼ãã®è² è·ãåæ£ãããã¨ãã§ãããµã¼ããã横ã«å¢ããã¦ãããã¹ã±ã¼ã©ããªãã£ãå®ç¾ã§ãããã©ã®ãµã¼ãã«ã©ã®ãã£ã³ã¯ããããã¨ããã·ã£ã¼ãæ å ±ã¯mongocã管çãã¦ããã
ããªããMongoDBã¯ãmongosãmongocãmongodããæ§æããããmongodã¯Shardingããããã¼ã¿ãã¼ã¹ãµã¼ãã¼ãmongocã¯ãã®ç®¡çæ å ±ãæã¤ãµã¼ãã¼ãmongosã¯ã¯ã©ã¤ã¢ã³ãã¨Shardingããããµã¼ãã¼ç¾¤ã仲ä»ããããã§ã¯ã¢ããªã±ã¼ã·ã§ã³ãµã¼ãã«åå± ããå½¢ã«ãªã£ã¦ããã
ãReplicaSetsã¯éåæã¬ããªã±ã¼ã·ã§ã³ã®ä»çµã¿ã§ãèªåã§ãã©ã¤ããªï¼ã»ã«ã³ããªæ§æãåããã¨ãã§ããããã©ã¤ããªææ ¼ã®æ±ºå®ã®ããã«å®ãµã¼ãã3å°ã¯å¿ è¦ã«ãªãï¼ãã ãæ票権ã®ã¿ãæã£ã¦ããããã»ã¹ãå©ç¨ãã¦ãµã¼ããå°ãªãä¿ã¤ãã¨ãå¯è½ï¼ã
ããããã£ãæ©è½ã«ãããã¢ããªå´ã®å®è£ ã³ã¹ãã¯è»½ããã¹ã±ã¼ã©ããªãã£ã¨åé·æ§ã確ä¿ããã·ã¹ãã ãæ§ç¯ã§ãããç¾å¨ã¯ã140å°ã¨ãã大è¦æ¨¡ã®MongoDB群ãéç¨ãã¦ãããããã§å¾ãããé害対å¿ãªã©ã®ãã¦ãã¦ã説æãããã
ãã¾ããåãµã¼ãããã»ã¹ã®ãã£ãã·ãã£ã»ãã©ã³ãã³ã°ã«ã¤ãã¦ãmongocã§ã¯åé·æ§ã¯åææ¸ãè¾¼ã¿ï¼2ãã§ã¼ãºã³ãããï¼ã§ç¢ºä¿ããã¦ããããã¹ã±ã¼ã©ããªãã£ããªãã®ã§æ½¤æ²¢ãªãªã½ã¼ã¹ã使ããç¶æ ãã¦ããã»ããããã¨ããã
ãmongodã¯å®æçã«ãã£ã¹ã¯ã«æ¸ãåºãã®ã§ããã£ã¹ã¯I/Oã«ã¯ããç¨åº¦ã®æ§è½ãå¿ è¦ã ã¨ãããã¾ãããã¼ã¿ãã¡ã¢ãªãã£ãã·ã¥ãããããã¡ã¢ãªã¯å¤ããã°å¤ãã»ã©ãããmongostatã§ç¶æ³ã確èªããã¨ã©ã¼ãå¤ããªã£ããã¡ã¢ãªãShardingã追å ããéç¨ãå¿ è¦ã ã
ããã®ã»ãéç¨ã®ãã¤ã³ãã¨ãã¦ã¯ãexplain()ã§ã¯ã¨ãªã®ç¢ºèªãããå¿ è¦ãªç®æã«indexãè²¼ããããã«ãããã¯ã¨ãªã®é«éåãå³ããã¨ãã§ããï¼ä¾ã§ã¯æ大100åã®é«éåãè¦ãããï¼ã2.0ã§é«éåã»ã³ã³ãã¯ãåããã¦ããã®ã§ãã¼ã¸ã§ã³ã¢ããããã»ããããã
ãããã¯ã¢ããã§ã¯ãfsyncã³ãã³ãã§ã¬ããªã±ã¼ã·ã§ã³ãä¸æåæ¢ãã¦dumpãåå¾ãããã·ã£ã¼ããã¨ã«å®è¡ãããã¨ã§å®å ¨ãªãã¼ã¿ãåãããã¨ãã°ãã¼ãã«ããã¯ãé¿ããããã«ã¯ãæ¸ãè¾¼ã¿ã®å¤ãã³ã¬ã¯ã·ã§ã³ãå¥ã®ã¯ã©ã¹ã¿ã«åãããä»å¾ãã³ã¬ã¯ã·ã§ã³ã¬ãã«ããã¯ãå®è£ ãããã°å¯¾å¿ããããã¨ã
ãChunkã®åãã¯AutoBalanceã§åæã«ç§»åãã¦ããããããã¼ã¿ã¢ã¯ã»ã¹é »åº¦ã§ã¯ãªãã®ã§ãæ°ããå ¥ã£ã¦ãããã¼ã¿ãé »ç¹ã«ã¢ã¯ã»ã¹ãããã¨è² è·åæ£ã«ãªããªããæåã§Chunkã移åãã¦ãã©ã³ã¹ããã¨ãå ¨mongosã®åèµ·åãå¿ è¦ã¨ãªãããéç¨ãå¿ è¦ã«ãªããä»å¾ã®èª²é¡ã ãã2.0ç³»ã§ã¯AutoBalanceãæ¹åããã¦ããããã ã
ããã®ããã«ä»æ§ãæ¹åã®ä½å°ã¯ãããã®ã®ã MongoDBã¯ã¹ã±ã¼ã©ããªãã£ã確ä¿ããè¦ç´ ã¯ååã«æã£ã¦ãããã½ã¼ã·ã£ã«ã²ã¼ã ãã¢ãã¤ã«ã²ã¼ã ã§éçºããã«ã¯ãããããã¯ãã§ããµã¼ãã¹ãå®å®éç¨ããªããæé·ãããããã«å¤§åãªè¦ç´ ã«ãªããã¨ããã®ããµã¤ãã¼ã¨ã¼ã¸ã§ã³ãã§ã®èªèã ã