MongoDB falla en horas no ocupadas

1

Estoy ejecutando un trabajo cron que consulta algunos datos de MongoDB durante la noche, cuando nadie más está usando MongoDB para leer o escribir datos, y recibo este error Error: server.lab:27017: Read timed out after reading 0 bytes, waited for 30.000000 seconds Durante el día, la consulta dura unos 60 ms para devolver datos. Tengo suficiente RAM, e incluso duplicarlo no ayuda. MongoDB se ejecuta en el sistema de archivos XFS. Yo uso la versión 3.2.3 (más nueva). Sé que MongoDB usa caché de Linux, y lo más probable es que el problema sea el mecanismo de calentamiento de MongoDB. ¿Que mas puedo hacer?

Aquí está la consulta.

db.event.aggregate([
{
     $match : {"schedule.sessions.attendance.0" : {$exists : true}}
},
{
    $unwind : "$schedule"
},
{
    $unwind : "$schedule.sessions"
},
{
    $project : {
    '_id' : false,
    'schedule.sessions.date_start' : 1,
    'schedule.sessions.date_finish' : 1,
    'schedule.sessions.attendance' : 1
    }
},
{
    $match : {
        "schedule.sessions.attendance.0" : {$exists : true},
        'schedule.sessions.date_start' : {$gte : ISODate("2016-02-14T20:00:00.000+0000"), $lt : ISODate("2016-02-15T20:00:00.000+0000") }
    }
}

])

La colección de eventos contiene alrededor de 5000 documentos.

Y aquí está la estructura del documento.

mongos> db.event.findOne()
{
    "_id" : ObjectId("563cc6993764872c268b45db"),
    "schedule" : [
        {
            "_id" : ObjectId("563cc6993764872c268b45d7"),
            "sessions" : [
                {
                    "_id" : ObjectId("5694d3c842600772f64bcc1a"),
                    "date_start" : ISODate("2016-02-08T11:30:00Z"),
                    "date_finish" : ISODate("2016-02-08T13:30:00Z"),
                    "place" : [ ],
                    "attendance" : [
                        ObjectId("55ed6d03b3b852c812003b92"),
                        ObjectId("55ed6ce1b3b852c8120023f2"),
                        ObjectId("55eee520b3b852ac930003cb"),
                        ObjectId("55ed6cfdb3b852c812003722"),
                        ObjectId("55ed6d01b3b852c812003a52"),
                        ObjectId("55ed6d01b3b852c812003a7d")
                    ],
                    "date_created" : null,
                    "date_updated" : null,
                    "shard_location_id" : null
                }
            ]
        },
        {
            "_id" : ObjectId("563cc6993764872c268b45d8"),
            "sessions" : [
                {
                    "_id" : ObjectId("5694d3c842600772f64bcc1b"),
                    "date_start" : ISODate("2016-02-15T11:30:00Z"),
                    "date_finish" : ISODate("2016-02-15T13:30:00Z"),
                    "place" : [ ],
                    "attendance" : [
                        ObjectId("55ed6d03b3b852c812003b92"),
                        ObjectId("55ed6ce1b3b852c8120023f2"),
                        ObjectId("55eee520b3b852ac930003cb"),
                        ObjectId("55ed6cfdb3b852c812003722"),
                        ObjectId("55ed6d01b3b852c812003a7d")
                    ],
                    "date_created" : null,
                    "date_updated" : null,
                    "shard_location_id" : null
                }
            ]
        },
        {
            "_id" : ObjectId("563cc6993764872c268b45d9"),
            "sessions" : [
                {
                    "_id" : ObjectId("5694d3c842600772f64bcc1c"),
                    "date_start" : ISODate("2016-02-22T11:30:00Z"),
                    "date_finish" : ISODate("2016-02-22T13:30:00Z"),
                    "place" : [ ],
                    "attendance" : [ ],
                    "date_created" : null,
                    "date_updated" : null,
                    "shard_location_id" : null
                }
            ]
        },
        {
            "_id" : ObjectId("563cc6993764872c268b45da"),
            "sessions" : [
                {
                    "_id" : ObjectId("5694d3c842600772f64bcc1d"),
                    "date_start" : ISODate("2016-02-29T11:30:00Z"),
                    "date_finish" : ISODate("2016-02-29T13:30:00Z"),
                    "place" : [ ],
                    "attendance" : [ ],
                    "date_created" : null,
                    "date_updated" : null,
                    "shard_location_id" : null
                }
            ]
        },
        {
            "_id" : ObjectId("56b9d21c376487714d2c1c0a"),
            "sessions" : [
                {
                    "_id" : ObjectId("56b9d21c376487714d2c1c09"),
                    "date_start" : ISODate("2016-02-14T11:30:00Z"),
                    "date_finish" : ISODate("2016-02-14T13:30:00Z"),
                    "place" : [ ],
                    "attendance" : [
                        ObjectId("55ed6d03b3b852c812003b92"),
                        ObjectId("55ed6ce1b3b852c8120023f2"),
                        ObjectId("55eee520b3b852ac930003cb"),
                        ObjectId("55ed6cfdb3b852c812003722"),
                        ObjectId("55ed6d01b3b852c812003a7d")
                    ],
                    "date_created" : null,
                    "date_updated" : null,
                    "shard_location_id" : null
                }
            ],
            "date_created" : ISODate("2016-02-09T11:48:44.400Z"),
            "date_updated" : ISODate("2016-02-09T11:48:44.400Z"),
            "shard_location_id" : null
        },
        {
            "_id" : ObjectId("56b9d24c376487794e2c1c0a"),
            "sessions" : [
                {
                    "_id" : ObjectId("56b9d24c376487794e2c1c09"),
                    "date_start" : ISODate("2016-02-21T11:30:00Z"),
                    "date_finish" : ISODate("2016-02-21T13:30:00Z"),
                    "place" : [ ],
                    "attendance" : [ ],
                    "date_created" : null,
                    "date_updated" : null,
                    "shard_location_id" : null
                }
            ],
            "date_created" : ISODate("2016-02-09T11:49:32.324Z"),
            "date_updated" : ISODate("2016-02-09T11:49:32.324Z"),
            "shard_location_id" : null
        },
        {
            "_id" : ObjectId("56b9d2583764870e4e2c1c0b"),
            "sessions" : [
                {
                    "_id" : ObjectId("56b9d2583764870e4e2c1c0a"),
                    "date_start" : ISODate("2016-02-28T11:30:00Z"),
                    "date_finish" : ISODate("2016-02-28T13:30:00Z"),
                    "place" : [ ],
                    "attendance" : [ ],
                    "date_created" : null,
                    "date_updated" : null,
                    "shard_location_id" : null
                }
            ],
            "date_created" : ISODate("2016-02-09T11:49:44.108Z"),
            "date_updated" : ISODate("2016-02-09T11:49:44.108Z"),
            "shard_location_id" : null
        },
        {
            "_id" : ObjectId("56c47ff416d37ce33f1e8144"),
            "sessions" : [
                {
                    "_id" : ObjectId("56c47ff416d37ce33f1e8143"),
                    "date_start" : ISODate("2016-03-06T11:30:00Z"),
                    "date_finish" : ISODate("2016-03-06T13:30:00Z"),
                    "place" : [ ],
                    "attendance" : [ ],
                    "date_created" : ISODate("2016-02-17T14:13:08.652Z"),
                    "date_updated" : ISODate("2016-02-17T14:13:08.652Z"),
                    "shard_location_id" : null
                }
            ],
            "date_created" : ISODate("2016-02-17T14:13:08.652Z"),
            "date_updated" : ISODate("2016-02-17T14:13:08.652Z"),
            "shard_location_id" : null
        }
    ],
    "subscription" : [
        {
            "_id" : ObjectId("56af42ff16d37c4901afc81d"),
            "user_id" : ObjectId("55ed6d00b3b852c8120039e7"),
            "status" : "approved",
            "type" : NumberLong(2),
            "date_created" : ISODate("2016-02-01T11:35:27.324Z"),
            "date_updated" : ISODate("2016-02-01T11:35:27.324Z")
        },
        {
            "_id" : ObjectId("56af441958f591da05954741"),
            "user_id" : ObjectId("55eee515b3b852ac9300024a"),
            "status" : "approved",
            "type" : NumberLong(2),
            "date_created" : ISODate("2016-02-01T11:40:09.034Z"),
            "date_updated" : ISODate("2016-02-01T11:40:09.034Z")
        },
        {
            "_id" : ObjectId("56af44b6f5417201179f6822"),
            "user_id" : ObjectId("55ed6cfcb3b852c8120036b5"),
            "status" : "approved",
            "type" : NumberLong(2),
            "date_created" : ISODate("2016-02-01T11:42:46.296Z"),
            "date_updated" : ISODate("2016-02-01T11:42:46.296Z")
        },
        {
            "_id" : ObjectId("56af450d16d37cb20aafc83c"),
            "user_id" : ObjectId("55ed6d03b3b852c812003b92"),
            "status" : "approved",
            "type" : NumberLong(2),
            "date_created" : ISODate("2016-02-01T11:44:13.048Z"),
            "date_updated" : ISODate("2016-02-01T11:44:13.048Z")
        },
        {
            "_id" : ObjectId("56af4543f541728c1a9f67d5"),
            "user_id" : ObjectId("55ed6ce9b3b852c812002924"),
            "status" : "approved",
            "type" : NumberLong(2),
            "date_created" : ISODate("2016-02-01T11:45:07.372Z"),
            "date_updated" : ISODate("2016-02-01T11:45:07.372Z")
        },
        {
            "_id" : ObjectId("56af458a16d37cb20aafc8c1"),
            "user_id" : ObjectId("55ed6cffb3b852c812003912"),
            "status" : "approved",
            "type" : NumberLong(2),
            "date_created" : ISODate("2016-02-01T11:46:18.765Z"),
            "date_updated" : ISODate("2016-02-01T11:46:18.765Z")
        },
        {
            "_id" : ObjectId("56af4612f54172991d9f67f5"),
            "user_id" : ObjectId("55ed6cd6b3b852c812001b93"),
            "status" : "approved",
            "type" : NumberLong(2),
            "date_created" : ISODate("2016-02-01T11:48:34.755Z"),
            "date_updated" : ISODate("2016-02-01T11:48:34.755Z")
        },
        {
            "_id" : ObjectId("56af45f116d37c680fafc8e3"),
            "user_id" : ObjectId("55ed6cfdb3b852c812003723"),
            "status" : "approved",
            "type" : NumberLong(2),
            "date_created" : ISODate("2016-02-01T11:48:01.395Z"),
            "date_updated" : ISODate("2016-02-01T11:48:01.395Z")
        },
        {
            "_id" : ObjectId("56af46bc16d37c2f11afc8ac"),
            "user_id" : ObjectId("55eee513b3b852ac9300020a"),
            "status" : "approved",
            "type" : NumberLong(2),
            "date_created" : ISODate("2016-02-01T11:51:24.653Z"),
            "date_updated" : ISODate("2016-02-01T11:51:24.653Z")
        },
        {
            "_id" : ObjectId("56af46e2376487b31fa41f34"),
            "user_id" : ObjectId("55eee519b3b852ac930002ca"),
            "status" : "approved",
            "type" : NumberLong(2),
            "date_created" : ISODate("2016-02-01T11:52:02.953Z"),
            "date_updated" : ISODate("2016-02-01T11:52:02.953Z")
        },
        {
            "_id" : ObjectId("56af4756f5417214259f67c0"),
            "user_id" : ObjectId("55ed6ce1b3b852c8120023f2"),
            "status" : "approved",
            "type" : NumberLong(2),
            "date_created" : ISODate("2016-02-01T11:53:58.595Z"),
            "date_updated" : ISODate("2016-02-01T11:53:58.595Z")
        },
        {
            "_id" : ObjectId("56af477af5417261259f67c3"),
            "user_id" : ObjectId("55eee520b3b852ac930003cb"),
            "status" : "approved",
            "type" : NumberLong(2),
            "date_created" : ISODate("2016-02-01T11:54:34.308Z"),
            "date_updated" : ISODate("2016-02-01T11:54:34.308Z")
        },
        {
            "_id" : ObjectId("56af478e376487a822a41f52"),
            "user_id" : ObjectId("55ed6d04b3b852c812003c02"),
            "status" : "approved",
            "type" : NumberLong(2),
            "date_created" : ISODate("2016-02-01T11:54:54.084Z"),
            "date_updated" : ISODate("2016-02-01T11:54:54.084Z")
        },
        {
            "_id" : ObjectId("56b87f27f54172375e7b23cb"),
            "user_id" : ObjectId("55ed6ce1b3b852c812002389"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:42:31.240Z"),
            "date_updated" : ISODate("2016-02-08T11:42:31.240Z"),
            "shard_location_id" : NumberLong(60074372)
        },
        {
            "_id" : ObjectId("56b87f27f54172375e7b23cc"),
            "user_id" : ObjectId("55ed6cdcb3b852c81200202d"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:42:31.269Z"),
            "date_updated" : ISODate("2016-02-08T11:42:31.269Z"),
            "shard_location_id" : NumberLong(85072479)
        },
        {
            "_id" : ObjectId("56b87f27f54172375e7b23ce"),
            "user_id" : ObjectId("55ed6cdab3b852c812001ea6"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:42:31.299Z"),
            "date_updated" : ISODate("2016-02-08T11:42:31.299Z"),
            "shard_location_id" : NumberLong(54819081)
        },
        {
            "_id" : ObjectId("56b87f27f54172375e7b23cf"),
            "user_id" : ObjectId("55ed6cdbb3b852c812001fba"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:42:31.331Z"),
            "date_updated" : ISODate("2016-02-08T11:42:31.331Z"),
            "shard_location_id" : NumberLong(65625871),
            "status_deleted" : NumberLong(1)
        },
        {
            "_id" : ObjectId("56b87f27f54172375e7b23d0"),
            "user_id" : ObjectId("55ed6ce9b3b852c812002929"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:42:31.360Z"),
            "date_updated" : ISODate("2016-02-08T11:42:31.360Z"),
            "shard_location_id" : NumberLong(79641334)
        },
        {
            "_id" : ObjectId("56b87f27f54172375e7b23d1"),
            "user_id" : ObjectId("55ed6cfab3b852c812003504"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:42:31.388Z"),
            "date_updated" : ISODate("2016-02-08T11:42:31.388Z"),
            "shard_location_id" : NumberLong(94737821)
        },
        {
            "_id" : ObjectId("56b8806df5417242647b23c7"),
            "user_id" : ObjectId("55ed6cfeb3b852c812003845"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:47:57.320Z"),
            "date_updated" : ISODate("2016-02-08T11:47:57.320Z"),
            "shard_location_id" : NumberLong(66955040)
        },
        {
            "_id" : ObjectId("56b8806df5417242647b23c8"),
            "user_id" : ObjectId("55ed6cfab3b852c812003596"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:47:57.349Z"),
            "date_updated" : ISODate("2016-02-08T11:47:57.349Z"),
            "shard_location_id" : NumberLong(83983525)
        },
        {
            "_id" : ObjectId("56b8806df5417242647b23c9"),
            "user_id" : ObjectId("55ed6d00b3b852c8120039ac"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:47:57.544Z"),
            "date_updated" : ISODate("2016-02-08T11:47:57.544Z"),
            "shard_location_id" : NumberLong(70202545),
            "status_deleted" : NumberLong(1)
        },
        {
            "_id" : ObjectId("56b8806df5417242647b23ca"),
            "user_id" : ObjectId("55ed6d03b3b852c812003b98"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:47:57.572Z"),
            "date_updated" : ISODate("2016-02-08T11:47:57.572Z"),
            "shard_location_id" : NumberLong(83981351)
        },
        {
            "_id" : ObjectId("56b8806df5417242647b23cb"),
            "user_id" : ObjectId("55ed6cfdb3b852c812003722"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:47:57.630Z"),
            "date_updated" : ISODate("2016-02-08T11:47:57.630Z"),
            "shard_location_id" : NumberLong(68552635)
        },
        {
            "_id" : ObjectId("56b8806df5417242647b23cc"),
            "user_id" : ObjectId("55ed6cffb3b852c812003894"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:47:57.748Z"),
            "date_updated" : ISODate("2016-02-08T11:47:57.748Z"),
            "shard_location_id" : NumberLong(80433985)
        },
        {
            "_id" : ObjectId("56b8806df5417242647b23cd"),
            "user_id" : ObjectId("55ed6cfbb3b852c8120035ed"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:47:57.957Z"),
            "date_updated" : ISODate("2016-02-08T11:47:57.957Z"),
            "shard_location_id" : NumberLong(67251008)
        },
        {
            "_id" : ObjectId("56b8806ef5417242647b23ce"),
            "user_id" : ObjectId("55ed6d01b3b852c812003a52"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:47:58.029Z"),
            "date_updated" : ISODate("2016-02-08T11:47:58.029Z"),
            "shard_location_id" : NumberLong(98099161)
        },
        {
            "_id" : ObjectId("56b8806ef5417242647b23cf"),
            "user_id" : ObjectId("55ed6d01b3b852c812003a7d"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:47:58.106Z"),
            "date_updated" : ISODate("2016-02-08T11:47:58.106Z"),
            "shard_location_id" : NumberLong(87539171)
        },
        {
            "_id" : ObjectId("56b8806ef5417242647b23d0"),
            "user_id" : ObjectId("55ed6cffb3b852c81200391d"),
            "type" : NumberLong(1),
            "status" : "approved",
            "date_created" : ISODate("2016-02-08T11:47:58.229Z"),
            "date_updated" : ISODate("2016-02-08T11:47:58.229Z"),
            "shard_location_id" : NumberLong(78085842)
        }
    ],
    "media" : [ ],
    "template_id" : ObjectId("5626c6c3b3b852bc31007ad6"),
    "title_en" : "3D Modeling I",
    "group_id" : ObjectId("563cc6993764872c268b45d5"),
    "user_slots" : [
        "15:30"
    ],
    "date_start" : ISODate("2016-02-07T20:00:00Z"),
    "date_finish" : ISODate("2016-03-05T20:00:00Z"),
    "place_id" : null,
    "points" : null,
    "date_created" : ISODate("2015-11-06T15:26:17.468Z"),
    "date_updated" : ISODate("2016-02-17T14:01:07.769Z"),
    "shard_location_id" : NumberLong(84354891),
    "shifted" : 5,
    "title_hy" : "3D մոդելավորում I",
    "public_access" : "0",
    "location_access" : [
        NumberLong(0)
    ],
    "description_hy" : "",
    "description_en" : "",
    "min_age_access" : "",
    "max_age_access" : "",
    "max_users" : ""
}
Edik Mkoyan
fuente
¿Puedes rastrear la consulta que estás ejecutando en los registros? Todavía se completará incluso después de que se haya agotado el tiempo del lado del cliente, y luego podrá ver cuánto tiempo tarda en regresar, lo que puede proporcionar más información. También sería bueno ver una explicación sobre la consulta
Adam C
He habilitado la creación de perfiles, no registra nada, todas mis consultas tienen menos de 100 ms, sin embargo, mongotop dice que en algunas colecciones algunas operaciones toman 5 segundos, eso es confuso. No traté de explicar, creo que el perfil debería responder la pregunta, ¿no?
Edik Mkoyan
mongotop es solo una vista de cuán ocupadas están las colecciones particulares, es una estadística acumulativa basada en toda la actividad en una colección, por lo que no es particularmente útil para solucionar un problema de consulta única. Si sus consultas no se muestran en el registro, no demoran más de 30 segundos y su tiempo de espera está siendo causado por algo más. Es hora de verificar si el lugar desde el que lo está ejecutando tiene la conectividad adecuada, ver si hay un error tipográfico en algún lugar, etc., especialmente si esto funciona rápidamente cuando lo ejecuta manualmente
Adam C
siempre funciona cuando lo ejecuto por segunda vez con un ligero retraso.
Edik Mkoyan
1
sin discutir sobre lo que está viendo, no dudo de la secuencia, más aún acerca de cuál es la causa. Si una consulta está tardando tanto en ejecutarse, definitivamente se mostrará en los registros; si no hay consultas que se muestren en absoluto con tiempos extendidos, entonces está sucediendo algo extraño. Comenzaría a buscar algo que (por ejemplo) elimine las consultas de larga duración, o ver si una captura de paquetes muestra algo extraño sobre la primera ejecución. Del mismo modo, intentaría ejecutarlo manualmente fuera de las horas, tal vez con una explicación al menos una vez para ver si sucede lo mismo.
Adam C