parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

High Latency for push notifications using parse-server-sns-adapter module via parse-server

Open sprabs opened this issue 10 years ago • 1 comments

I am currently executing a call in the afterSave trigger for my "Messages" class that sends push notifications to select users. We have configured parse-server-sns-adapter (~0.0.7 in package.json) and have confirmed through the AWS SNS UI that the endpoints are properly added and the push notifications are sent and received fine.

Steps to reproduce

Here is the setup in our index.js (snippet):

var pushConfig =  { pushTypes : { android: {ARN : [REDACTED]},
                                  ios: {ARN: [REDACTED], production: false, bundleId: "com.something.dev"}
                                 },
                    accessKey: process.env.SNS_ACCESS_KEY,
                    secretKey: process.env.SNS_SECRET_ACCESS_KEY,
                    region: "us-east-1"
                  };

var SNSPushAdapter = require('parse-server-sns-adapter');
var snsPushAdapter = new SNSPushAdapter(pushConfig);
pushConfig['adapter'] = snsPushAdapter;

var api = new ParseServer({
  databaseURI: databaseUri,
  appId: process.env.APP_ID || 'myAppId',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'http://localhost:1337',  // Don't forget to change to https if needed
  webhookKey: process.env.WEBHOOK_KEY || 'hook',
  push: pushConfig,
  verbose: true
});

Here is the query we have for sending pushes:

var pushQuery = new Parse.Query(Parse.Installation);
    pushQuery.containedIn("activeUser", toUserPointers, { useMasterKey: true });
    Parse.Push.send({
      where: pushQuery,
      data: notificationData
    }, { useMasterKey: true }).then( function() {
          promise.resolve("Push notification successfully sent!");
       }, function(error) {
          promise.reject("Error while sending push notification: " + error.message);
       }
    );

As I mentioned above, this is triggered from the afterSave. When I create 10 simultaneous requests (saving object to Messages class) from just two devices (each sending a push notification to 9 other devices), it forces the latency to go up (like 10-15 seconds in some cases) for the full system. I can confirm it is not something fundamental with the afterSave itself getting triggered because I tried commenting out the promise that sends the push notifications and it resolved the latency problem completely.

What am I doing wrong with the pushQuery? Clearly, it's causing a strain on the system that makes it not production ready. I've already switched to SNS based on the feedback from @flovilmart and others when explaining some of the limitations of push on parse server.

Environment Setup

  • Server
    • parse-server version: 2.2.19
    • Operating System: 64bit Amazon Linux 2016.03 v2.1.3 running Node.js
    • Hardware: t2.medium (AWS EC2)
    • Localhost or remote server? AWS Elastic Beanstalk
  • Database
    • MongoDB version: 3.2.7 (MMAPv1)
    • Hardware: Shared (this is a dev database)
    • Localhost or remote server? mLab

sprabs avatar Sep 12 '16 19:09 sprabs

I've already switched to SNS based on the feedback from @flovilmart and others when explaining some of the limitations of push on parse server.

Switching over SNS won't change anything as the processing remains the same as long as you use Parse.Push.send.

On your pushQuery, are all the fields properly indexed?

flovilmart avatar Sep 13 '16 02:09 flovilmart