Hardware resources provided by your Atlas cluster
The performance of your Realm Application relies on the hardware resources provided by your linked Atlas cluster when Realm is querying your Atlas instance. To check whether the Realm performance issue was due to under-provisioned Atlas instance size or insufficient hardware resources, check the following metrics of your Atlas cluster, including but not limited to:
Normalized System CPU chart
If you observe high values on the above metrics, consider upgrading the instance size or provisioning more hardware resources.
Roles and rules
Roles are sets of document-level and field-level CRUD permissions and are chosen individually for each document associated with a query. Roles consist of rules which are defined for entire collections in a linked MongoDB Atlas cluster and apply to individual documents in the collection dynamically based on the application user that issued a query.
Since rules are applied at document level, there can be significant performance impact. You can define filters on incoming queries that Realm evaluates and applies before its initial query to your MongoDB cluster. Adding a filter to a collection can improve query performance by reducing the number of documents for which Realm needs to evaluate a role. To improve performance, consider using filters before using roles.
You can find more information about your rules’ performance in the logs of your MongoDB Realm Application.
Realm App Deployment Model and Region
Globally deployed Realm applications are hosted in every cloud region that Realm supports. The Realm SDKs automatically execute application requests, such as reading user information or calling a function, in the cloud region that’s closest to the user that issued the request.
Write operations to a linked MongoDB cluster are handled within a single region that you specify when you create your application. By default, Realm handles writes in the region closest to your application’s original linked MongoDB cluster. However, it is possible that requests can get routed to other regions and end up making many cross-region requests, which negatively impacts performance.
Locally deployed Realm applications are hosted in the cloud region that you specify when you first create your application. Application requests and MongoDB write operations will all be handled exclusively in the specified region. By default, local applications are deployed in the region that is closest to your application’s initial linked Atlas cluster or us-east-1 if there is no linked cluster.
For more information, see Deployment Models & Regions.
Rate of triggers being fired
Realm limits the execution of trigger functions to a rate of 1000 executions per second across all triggers in an application. If additional triggers fire beyond this threshold, Realm adds their associated functions to a queue and executes the functions after capacity becomes available.
Note that the real execution rate in your environment is also subject to different parameters and can be lower than the theoretical hard limit. For example, ordered triggers can greatly reduce the real triggers/second execution value; ordered triggers wait to execute a function for a particular event until the functions of previous events have finished executing. Consequently, ordered triggers are effectively rate-limited by the run time of each sequential trigger function.
Consult Realm triggers and performance issues for steps on how to mitigate this limitation.