Reputation: 33
Currently I'm working in a project that have a seriously problem of Overembedding because in only one collection are located 3 objects (arrays) inside this, which contains practically the 70% of the bussiness model of the app (we received this project from other developer team and was a complete Challenge). The another concern is that, the app uses realtime to tracking using geolocations, and continuosly uses this collection.
My cuestion is, I am totally sure that the problems with overload in the DB server and the slow down in some hours for the app was caused for this reason Overembedding.
We think that the solution is to made a new data base schema (undestanding that MongoDB is schema free but however is not a limitant) in that try to normalize this three objects in tree collections with low references (emulating the foreing keys like as the Relational model), but, you recommend for example, design and make a Datawarehouse with the old (current) DB, for made only read querys and only migrate the user data or migrate all the database to the new model (that maybe very very complicated... or not?)...
Aditional Information: Stats of Buses Collection
{
"ns" : "pruebas.buses",
"count" : 1343,
"size" : 38393616,
"avgObjSize" : 28587,
"numExtents" : 7,
"storageSize" : 58277888,
"lastExtentSize" : 20643840.0,
"paddingFactor" : 1.0,
"paddingFactorNote" : "paddingFactor is unused and unmaintained in 3.0. It remains hard coded to 1.0 for compatibility only.",
"userFlags" : 1,
"capped" : false,
"nindexes" : 1,
"totalIndexSize" : 65408,
"indexSizes" : {
"_id_" : 65408
},
"ok" : 1.0
}
This is a Document example from this collection called Buses:
{
"_id" : "BAOB-02",
"school" : "BAOBAB",
"licensePlate" : "UFS 118",
"color" : "BLANCO",
"model" : 2002,
"username" : "baobab02",
"students" : [
{
"firstNames" : "MATTHIAS ",
"lastNames" : "GARCIA VELANDIA",
"_id" : "1002",
"classroom" : "",
"blood" : "",
"telephone" : null,
"cellphone" : null,
"guardians" : [
{
"firstNames" : "GUSTAVO ",
"lastNames" : "GARCIA GARAVITO",
"_id" : ObjectId("553515248a854eba40c1d2fc")
},
{
"firstNames" : "CLAUDIA ",
"lastNames" : "VELANDIA ",
"_id" : ObjectId("553515248a854eba40c1d2fb")
}
],
"parents" : [
{
"firstNames" : "GUSTAVO ",
"lastNames" : "GARCIA GARAVITO",
"telephone" : null,
"cellphone" : 3103247894.0,
"email" : "[email protected]",
"_id" : ObjectId("553515248a854eba40c1d2fe")
},
{
"firstNames" : "CLAUDIA ",
"lastNames" : "VELANDIA ",
"telephone" : null,
"cellphone" : 3102487056.0,
"email" : "[email protected]",
"_id" : ObjectId("553515248a854eba40c1d2fd")
}
],
"addressInfo" : {
"pm" : {
"address" : "KM 2 TABIO - CAJICA",
"apartment" : "",
"neighborhood" : "VIA TABIO",
"monday" : true,
"tuesday" : true,
"wednesday" : true,
"thursday" : true,
"friday" : true,
"saturday" : false,
"coords" : [
4.9242399390697,
-74.0441983938217
],
"stopOrder" : 1
},
"am" : {
"address" : "NA",
"apartment" : "",
"neighborhood" : "",
"monday" : false,
"tuesday" : false,
"wednesday" : false,
"thursday" : false,
"friday" : false,
"saturday" : false,
"coords" : []
}
},
"code" : "1002"
},
{
"firstNames" : "JUAN PABLO",
"lastNames" : "ROMERO GUZMAN",
"_id" : "1003",
"classroom" : "",
"blood" : "",
"telephone" : null,
"cellphone" : null,
"guardians" : [
{
"firstNames" : "NELSON ANDRES",
"lastNames" : "ROMERO ",
"_id" : ObjectId("5535158b8a854eba40c1d300")
},
{
"firstNames" : "ANA MARIA",
"lastNames" : "GUZMAN MORENO",
"_id" : ObjectId("5535158b8a854eba40c1d2ff")
}
],
"parents" : [
{
"firstNames" : "NELSON ANDRES",
"lastNames" : "ROMERO ",
"telephone" : null,
"cellphone" : 3192997309.0,
"email" : "[email protected]",
"_id" : ObjectId("5535158b8a854eba40c1d302")
},
{
"firstNames" : "ANA MARIA",
"lastNames" : "GUZMAN MORENO",
"telephone" : null,
"cellphone" : 3143095644.0,
"email" : "[email protected]",
"_id" : ObjectId("5535158b8a854eba40c1d301")
}
],
"addressInfo" : {
"pm" : {
"address" : "CRR 7 2 46",
"apartment" : "APT. 404 INT. 8",
"neighborhood" : "CAPELLANIA",
"monday" : true,
"tuesday" : true,
"wednesday" : true,
"thursday" : true,
"friday" : true,
"saturday" : false,
"coords" : [
4.91861203215498,
-74.0340435504913
],
"stopOrder" : 2
},
"am" : {
"address" : "NA",
"apartment" : "",
"neighborhood" : "",
"monday" : false,
"tuesday" : false,
"wednesday" : false,
"thursday" : false,
"friday" : false,
"saturday" : false,
"coords" : []
}
},
"code" : "1003"
}
],
"auxiliary" : {
"firstNames" : "LEIDY VIVIANA",
"lastNames" : "MORANTES BARON",
"telephone" : null,
"cellphone" : 3203178186.0,
"email" : "[email protected]"
},
"driver" : {
"firstNames" : "VICTOR JULIO",
"lastNames" : "MORANTES MORANTES",
"telephone" : null,
"cellphone" : 3118955381.0
},
"__v" : 13
}
This collection contains inside Students +- 18 and each Student have 2 parents generally. Currently exists 1300 documents. The data of realtime geolocation tracking is allocaten in another collections, but the project uses another server for REDIS caching (I know that is not a good practice to caching all the database, but we are planning to segment this caching only for tracking services)
And the stats of all the DB>
{
"db" : "pruebas",
"collections" : 20,
"objects" : 5785288,
"avgObjSize" : 285.557788652873,
"dataSize" : 1652034048.0,
"storageSize" : 2388484096.0,
"numExtents" : 112,
"indexes" : 18,
"indexSize" : 176544368.0,
"fileSize" : 4226809856.0,
"nsSizeMB" : 16,
"extentFreeList" : {
"num" : 0,
"totalSize" : 0
},
"dataFileVersion" : {
"major" : 4,
"minor" : 22
},
"ok" : 1.0
}
PD/ A month ago, we probably would applied optimization techniques for MongoDB like Sharding or replication with load balancers and Mongos... but whatever, we understand that if the database was wrong designed, the best form to solve the problem is make a new model. And thanks, if someone take the time to read all this weird case.. and thanks in advance if make constructive comments and recommendations
Upvotes: 0
Views: 160
Reputation: 1189
In the above description, root cause is not mentioned and looks like based on assumption, brodriguezs is heading for a schema change
Few tips before schema is modified.
You can see few important tips here - https://docs.mongodb.com/manual/administration/analyzing-mongodb-performance/
Upvotes: 1