Extremely slow execution of an external dependency function

I am using mmwr-week package. For some reason it takes about 30 seconds on average to run the following code in Realm while it takes about 0.15 seconds on my MacBook Pro:

exports = function(){
  const mmwr = require("mmwr-week");
  let mdate = new mmwr.MMWRDate();
  const d = new Date();
  for (let i = 0; i < 1000; i++) {
    mdate.fromJSDate(d);
  }
};

Any ideas why there is a ~200x difference in performance?

Hey Ilya,

There are some improvements we have planned to make dependency resolution a bit faster over the next few months. In the meantime, I would suggest looking into an alternative package if the latency is blocking.

1 Like

Hi Sumedha, just to clarify: the dependency itself is loading quickly. It’s a very simple function call (inside the loop) that is very slow.

@Sumedha_Mehta1 whatever happened here? I’m having the same issue with Stripe. It’s taking 1 minute and 15 seconds to complete a simple call to list customers by email address. The function executes quickly (including loading the dependencies with require) up until I call stripe.customers.list. This same call take < 100 ms on my local machine or within a Firebase function. Something is definitely wrong.

1 Like

@Byron_Sorrells do you have an idea of when this started happening?

Today. It’s a brand new function in a new project. I’ve also opened a support ticket and Manny is looking into it.

Did you solve your issue. could it be that when calling a third party api, realm function is getting a cors error or some sort of network issue?

No, it’s not solved. This is what I got back from support:

I was able to reproduce this on my side using your simplified code sample and it also took 1m15s for me.

After researching further I found that this is a known issue on our side when using the Stripe API in functions where requests are taking up to 50-60 seconds to complete. This is a known issue on our side with how we’re handling the Stripe request and our Engineering team are currently in the process of analysing the issue.

Unfortunately I don’t have an ETA to provide you with for when this will be fixed, however I will track the work on our side and update you in this case when there is progress.

This is extremely disappointing and leads me to believe that Realm triggers / Mongodb Functions are not production-ready as a lambda drop in replacement… I think Triggers/Realm Functions would only be suitable for Mongo Actions that require no additional third party dependencies. If stripe connections are taking more than 4 seconds to complete you have a problem. I personally am using Lambda’s and Cloudflare functions, was thinking about realm triggers but after this, i will hold off.

1 Like

Based on the reply from support, they seem to claim it’s Stripe only. I ended up not using the stripe node SDK and I wrote the requests manually using the http service. Not a huge deal and somewhat annoying, but not the end of the world. Everything works great (including the triggers).

Hi all - we’re still investigating why the stripe dependency is slower, unfortunately it’s not as straightforward to fix as hoped. I do want to call out that our dependency functionality is still in beta and if you’re having issues with them, there are immediate work arounds (such as calling the API directly). However, we’re carefully monitoring any dependency bugs that show up and filing tickets to address them. If any other part of Realm is not working as expected, please let us know!

Thanks for the quick updates @Sumedha_Mehta1. Everything else is working great. And calling the API directly works fine for now.

Is there any update from the MongoDB team on the usability of the Stripe SDK? I am also seeing timeouts when I try to do anything.

This is not Stripe only, I have the same issue with Algolia.

In my case it just times out and don’t update Algolia.

My function is a simple database trigger, that updates the object to Algolia with “saveObject”. The function runs fine, nothing is slow regarding the required dependency, then, at the index.saveObject the functions just hangs out forever, and Algolia is not even updated.

My guess it’s something regarding network. But looks very much like this issue with Stripe.

It’s a very important fix, basically kills the Realm Functions, and I am about to integrate Stripe too.

Hello MongoDB, did you get improvements on this executions times? I am about to integrate payments through Stripe into my app, and I can’t loose sales. If I loose sync to Algolia, I can recover later, but that is not feasible for sales.

I use Realm Password Auth for my app, so relying on Realm Functions is wanted, where I can check the auth state. So having Stripe into the Realm Function is very very needed.

Thanks, I want to rely as much as possible into the MongoDb platform.

Realm Functions / Mongo Triggers have had little or no release updates (or atleast not disclosed) it seems this is not a focus they want to target as a lot of q’s remain unanswered. I myself have moved on to Lamda and Cfloudflare functions to solve my problems… Yes its a pain as Realm Auth was good, but that too has seen no improvement and no mentioned of passwordless auth.

If you are a enterprise customer you should get a reply or try online chat support.

Thanks @Rishi_uttam for you time to reply.

Indeed very sad for MongoDB.

Rishi, may I ask, on your move to Lambda and Cloudflare, do you still use the Realm Auth? Did that work?

I believe I can confirm the access token is valid with this API below, just would like to know if you used it and if that worked fine? https://docs.mongodb.com/realm/reference/authenticate-http-client-requests/#verify-a-client-access-token

I have 4k users on Realm Auth, so really can’t move to another provider too soon.

Thank you very much.

I have the same issue using the AWS-SDK in MongoDB functions. When I try to upload an image to a S3 bucket it takes around 30 to 60 seconds! When I try this on my local machine or a different location it takes around 150ms.

1 Like

uploading a object to s3 shouldnt be slower as you are uploading to an s3 url.

It is though. This is the code:

let buf = Buffer.from(
         base64.replace(/^data:image\/\w+;base64,/, ""),
         "base64"
       );


const uploadParams = {
         Bucket: "BUCKETNAME",
         Body: BUFFERFILE,
         Key: fileName,
         ContentEncoding: "base64",
         ContentType: "image/jpeg",
       };

       s3.upload(uploadParams, function (err, data) {
         if (err) {
           console.log(err);
           console.log("Error uploading data: ", data);
         } else {
           console.log("succesfully uploaded the image!");
         }
       });