Data API (beta) - seems very slow to access data

I have been testing out mongodb atlas new Data-API.

I have found quite a big hurdle in the way the length of time it takes for a simple document to be returned using /findOne

In comparison , I am using a aws lambda function using the normal node driver to create a database connection to my atlas cluster. Every time the function runs cold the total connection time is about 3 seconds. (warmup, create connection to atlas, query and return the data)
However when the function is warm and the database connection is re-used the round trip time to get data is ranges from 200-800ms (huge difference)

I expected that the data-api would perform much better, but on average it is about 3-4 seconds, and never better on subsequent tries.

Does it mean the using the data api to http://data.mongodb-api.com/xxxx which i believe behind the scenes invokes another cloud function and therefore is always cold and the db connection is always closed?

Using a simple data-set the data-api seems very slow when using the drivers.

Any support on what I may be doing wrong would be appreciated.

1 Like

Hey Rishi - thanks for your feedback! It would be helpful to understand a little bit more about your scenario. While the API will ineviatably have another hop before reaching the database given it’s going via a HTTPS connection, I’m curious about -

  1. your Atlas tier
  2. Region you’re invoking the request from
  3. Cloud provider and region of your backing cluster.
  4. When you tested this out

3-4s is unexpected and thank you for bringing this to our attention!

Hello, and thanks for the reply.

  1. My atlas tier is M1 shared HKG region AWS (i seldom get over 20 + connections and using a database that is currently less then 30MB, the http response payload is only 1-2kb, infact i am just returning a small document for testing.

  2. region is Hong Kong AWS. I am also invoking my lamda from Hong Kong, the connecting to lambda is super fast, (as it is with the mongo node driver to my atlas db )

  3. but when i use the data-api i find their is no caching of open db connections on mongo’s side? Does the data-api create a new connection each time? this would certaintely make the request slow. This has not been documented as far as I know, I would like to know how the data -api is working behind he scenes, is a function being called (similar to realm-web?)

  4. Yes HTTPS does carry some overhead, but still, 4 seconds to findOne is slow, my lamda function using node driver is also creating a https connection to Atlas using the connection string is it not?

  5. My last test was lask week, i will try to follow-up with some screenshots with dev tools showing the total time.

  6. Yes 3-4 seconds is perhaps OK on first try, but subsequent tries should be within 200ms, it is for this reason we have refrained form using the DATA-API as it is too slow right now.

My data api is using the global URI as mentioned in my post : http://data.mongodb-api.com/xxxx… I believe this means it would auto select the closest region (out of 4)

I am happy to conduct more testing should you need, or if you have any results on your side I would very much like to see them.

Thanks
Rishi

i would like to know do others also ex

Hi Rishi -

  • we are selecting the closest region, but the closest one to you is currently located in Sydney, which is why it might be taking longer - we have plans to allow the singapore region in AWS shortly, so that will help a little bit.

  • We do some caching, I’m curious if you’re still running into this today - we had some issues on our end around mid April and I’m wondering if it was related to that

  • Scaling up the cluster might help out a little bit, so will optimizing for the payload size by projecting only what you need in each request. How big is your payload for the find?

I’ll send a dev tools report in order to provide more context to this issue.

It would be good if there was a deep dive video into the DataAPI and how the backend works with requests/cahching/opening closing of DB connections and how these are re-used. I did watch some live mongodb videos, but they dont discuss this.

My payload is literaly 1 byte, so scaling up should not make a difference at all, infact the free tier should be a perfect use case to measure speed and reliability going forward.

At the current rate of 4 seconds response time, it is way too long even for simple hobby apps.
I am getting better response times using the mongodbDB node driver on a cloud function.
Yes certainly Atlas & Relam need more edge locations for realm-web and the DataAPI.