How to correctly use realm on several instances like pm2?


#1

I’m developing a small api server. The version used here is as follows.

  • windows 10
  • nodejs v8.12.0
  • realm v2.16.1
  • pm2 v3.2.2

I run several instances using pm2’s cluster_mode.

┌────────────┬────┬─────────┬───────┬────────┬─────────┐
│ App name   │ id │ mode    │ pid   │ status │ restart │ uptime │ cpu │ mem       │ user │ watching │
├────────────┼────┼─────────┼───────┼────────┼─────────┤
│ apiServer  │ 0  │ cluster │ 8052  │ online │ 0       │ 14s    │ 0%  │ 48.0 MB   │ USER │ disabled │
│ apiServer  │ 1  │ cluster │ 14344 │ online │ 0       │ 14s    │ 0%  │ 48.5 MB   │ USER │ disabled │
│ apiServer  │ 2  │ cluster │ 15236 │ online │ 0       │ 13s    │ 0%  │ 48.4 MB   │ USER │ disabled │
└────────────┴────┴─────────┴───────┴────────┴─────────┘

When I run one instance without using pm2, or when I run only one instance using pm2, the CRUD works fine in the realm. but, in some instances, CRUD does not work properly.

  • one instance: PUT / borad / 1 200 19.813 ms
  • several instances in pm2’s cluster_mode: No response (PUT / borad / 1 200 51754.157 ms, which happens to be accidentally logged when doing other actions)

What is the proper way to use realm on several instances using a process manager, such as cluster(built-in module) or pm2?


#2

@sjh836 Realm node.js clients do write state locally which from the pm2 documentation appears could be problematic. The Realm apps need to be set to write to separate realm files and folders on the server and it should work but unclear if pm2 is expecting another configuration with state.