What is the best Mongodb Sharding key for my schema? -


i design mongodb collection can save statistic daily volume

here db schema

mongos> db.arq.findone() {     "_id" : objectid("553b78637e6962c36d67c728"),     "ip" : numberlong(635860665),     "ts" : isodate("2015-04-25t00:00:00z"),     "values" : {         "07" : 2,         "12" : 1     },     "daily_ct" : 5 } mongos> 

and here indexes

mongos> db.arq.getindexes() [     {         "v" : 1,         "key" : {             "_id" : 1         },         "name" : "_id_",         "ns" : "query_volume.test"     },     {         "v" : 1,         "key" : {             "ip" : 1         },         "name" : "ip_1",         "ns" : "query_volume.test"     },     {         "v" : 1,         "key" : {             "ts" : 1         },         "name" : "ts_1",         "expireafterseconds" : 15552000,         "ns" : "query_volume.test"     } ] mongos> 

note: have time stamp index since need use ttl mechanism.

but sharding key has suggestion?

you have multiple options:

  1. {ts: 1} timestamp. data of ranges located together, key monotonically increasing, , i'm not sure, whether ttl index clean shard chunks. means: write load switches shard shard, , have shard high write load whereas other shards no writes data. pattern works nicely if query contiguous time ranges has downsides in writing.
  2. {ts: "hashed"} hash-based sharding. data sharded more or less evenly across shards. hash-based sharding distributes write load involves all shards (more or less) when querying data.

you need test, fits best reads , writes. sharding key depends on data structure , read/write patterns of application.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -