Extremely slow GraphQL performance even with very simple query and schema

I am trying to switch over from REST to GraphQL, and am experiencing horribly slow responses for queries. As in 5000-7000+ ms for a super simple, small request. I’ve spent days on this, tried everything, and am about to give up. Any help would be greatly appreciated.

I have greatly reduced the schema from the huge one auto-generated to a tiny one for testing (no difference), implemented filters (no difference), simplified the query to only return a few, have indexed the main field (helped a tiny bit), and have not resolvers or anything special at all.

I am on the M10 tier.

The schema:

{
  "title": "mlbgame",
  "properties": {
    "_id": {
      "bsonType": "string"
    },
    "_simulation": {
      "bsonType": "bool"
    },
    "date": {
      "bsonType": "string"
    },
    "endDate": {
      "bsonType": "date"
    },
    "gameInfo": {
      "bsonType": "string"
    },
    "gameStatus": {
      "bsonType": "string"
    },
    "id": {
      "bsonType": "string"
    },
    "minutesRemaining": {
      "bsonType": "int"
    },
    "percentComplete": {
      "bsonType": "double"
    },
    "sport": {
      "bsonType": "string"
    },
    "startDate": {
      "bsonType": "date"
    },
    "status": {
      "bsonType": "string"
    }
  }
}

The query:

query GamesForCalendar($dateFrom: DateTime!, $dateTo: DateTime!) {
    mlbgames(query: {startDate_gte: $dateFrom, startDate_lte: $dateTo}) {
      id
      status
      sport
      date
      startDate
      endDate
      gameInfo
      gameStatus
      minutesRemaining
      percentComplete
      _simulation
    }
  }

A sample log entry:

Function Call Location:
US-OR
GraphQL Query:
query GamesForCalendar($dateFrom: DateTime!, $dateTo: DateTime!) { mlbgames(query: {startDate_gte: $dateFrom, startDate_lte: $dateTo}) { id status sport date startDate endDate gameInfo gameStatus minutesRemaining percentComplete _simulation __typename } }
Compute Used:
18736722090 bytes•ms
Remote IP Address:
136.32.230.69
Rule Performance Metrics:
{
  "dfsdb.mlbgames": {
    "roles": {
      "default": {
        "matching_documents": 19,
        "evaluated_fields": 0,
        "discarded_fields": 0
      }
    },
    "no_matching_role": 0
  }
}

I have an index on startDate as well. The result set is only 6k. Please help! Surely I am missing something, or there is some explanation, as this is completely unusable.

Best,
Greg

@Pavel_Duchovny Hi, did I post this incorrectly or in the wrong place? It would have sure been nige to give GraphGL with my application to see if it would have been best, but never could get past this issue. And no-one responded. I thought I did a decent job of describing the issue, so hoped it would have been an easy fix.

Thanks.

Hi @Gregory_Fay sorry that we missed your original post! Do you happen to know the realm app deployment model and region that your atlas cluster is deployed in? Some things that may cause slower queries with GraphQL include

  • having an app deployed in a region different from that of the atlas cluster
  • no indexing (though it seems like you’ve got this one figured out)
  • going cross cloud (if your cluster is in Azure, Realm could be slower because it’s currently only hosted on AWS)
  • rules may cause some slowness, but a way to optimize is to use Filter

Let me know if one or more oof these things seems like it may be the issue here.

Hi @Sumedha_Mehta1

Thank you for the reply. I missed it, and it got buried. :slight_smile:

I had to go another direction for now but will try to recreate what I had and see if any of these suggestions solve the problem. I was so excited about GraphQL until I couldn’t get the basics to work!

Thanks,
Greg

Hi everyone

Just want to confirm that having an app deployed in a region different from the atlas cluster caused crazy slow GraphQL queries for me.

AWS Cape Town closest region for my purposes, but Realm apps cannot be deployed in Cape Town region, so they were deployed in the N-Virginia region. Terrible performance (5-8s for most basic query of 5 simple items). After changing it so that my cluster and realm app runs in the N-Virginia region the same query now takes 30-40ms.

Thanks for the advice @Sumedha_Mehta1.

/theuns