Skip to content

Extreme Latency when Using Google Cloud Functions and Cloud Datastore #2374

Closed

Description

Environment details

  • OS: Google Cloud Functions
  • Region: US Central
  • google-cloud-node version: 1.0.2

Steps to reproduce

I experience high latency (~1 to 2 seconds) with pretty much every action.

Simple example (runs through bable prior to deploy) -

static async addPerson() {
    try {
      const datastore = Datastore({
        projectId: projectId
      });
      const key = datastore.key('person');
      const person = {
        key: key,
        data: 
          [
            { name: 'last_name', value: 'Wright' },
			{ name: 'last_name_UPPER', value: 'WRIGHT' },
            { name: 'first_name', value: 'Richard' },
			{ name: 'first_name_UPPER', value: 'RICHARD' },
			{ name: 'email', value: '[email protected]' },
            { name: 'address_street', value: 'My Place', excludeFromIndexes: true },
            { name: 'address_city', value: 'City' },
            { name: 'address_state', value: 'State' },
            { name: 'address_zip', value: '12345' },
            { name: 'phone', value: '123.456.7890' },
            { name: 'date_of_birth', value: new Date(1901, 02, 03)},
            { name: 'create_time', value: new Date(Date.now()), excludeFromIndexes: true }
          ]
      };
      
      let saveResponse = await datastore.save(person);
      
      let person_id=saveResponse[0].mutationResults[0].key.path[0].id;
      return person_id;
    } catch (err) {
      console.log(err);
      return;
    }
  }

Activity

  1. ghost changed the title [-]Extreme Latency when Using Google Cloud Functions[/-] [+]Extreme Latency when Using Google Cloud Functions and Cloud Datastore[/+] on Jun 10, 2017
  2. stephenplusplus commented on Jun 10, 2017

    @stephenplusplus
    Contributor

    Can you see if subsequent calls also have a lag? The first request has to sort out the authentication details, so it's known to be slower.

  3. stephenplusplus commented on Jun 12, 2017

    @stephenplusplus
    Contributor

    since when using cloud functions, the penalty is incurred on each http invocation the overhead is still very high (i.e. 0.8s per HTTP call).

    Yes, unfortunately. I'll close the issue, as we can't do anything within the client library. If any ideas come to mind for how this can be addressed, feel free to discuss.

  4. added
    api: datastore
    on Jun 12, 2017
  5. ro-savage commented on Aug 7, 2017

    @ro-savage

    @stephenplusplus - We are running into the same issue. Datastore and Functions seem like the perfect combination, paying only a per-request cost. However the latency is much too high to be usable in real-world.

    As was mentioned, it is related to the Auth.

    This problem must be solvable, as other similar systems such as Lambda + DynamoDB don't under into this issue.

    It seems unlikely to be implemented in node, but probably some setup on the function/lambda that is 'pre-authenticated' (AWS IAM roles?).

    Who would be the correct team/repo to work on this issue?

  6. reco commented on Aug 28, 2017

    @reco

    @ro-savage we were/are using app engine with datastore. we also did run in to big issues with the latency of the datastore. would love to hear some updates @google-admin about this issue.

  7. ahume commented on Sep 26, 2017

    @ahume

    A few weeks into development, we're finding Datastore to not be a viable solution for use in Functions due to the consistently poor performance on even very simple queries. 4000ms on first (authenticating) request, and then 800-1200ms afterwards.

  8. ignaciovazquez commented on Oct 3, 2017

    @ignaciovazquez

    We are also experiencing 60ms-200ms latencies on a lookup by key (runQuery is even worse) from GAE Flexible in node.

  9. stephenplusplus commented on Nov 6, 2017

    @stephenplusplus
    Contributor

    Also reported in #2727

    @lukesneeringer this seems to be a common problem. The most recent report shows 10 seconds spent on a query that should take in the tens of milliseconds. Worth considering, our Datastore API uses the REST endpoint (correction: our Datastore API uses common-grpc / manual proto loading with gRPC). There is a GAPIC layer that we will likely convert to during our repo extraction.

  10. EJB3927 commented on Nov 6, 2017

    @EJB3927

    Thank you @stephenplusplus. I can confirm I'm having this issue with the following environment:

    • OS: macOS Sierra
    • Node.js version: 7.10.0
    • npm version: 4.2.0
    • google-cloud/datastore version: 1.1.0

    Additionally, I'm noticing the issue on Cloud Functions with the same node and NPM versions.

  11. 14 remaining items

  12. lc-chrisbarton commented on Dec 11, 2017

    @lc-chrisbarton

    We use --memory=1024MB in order to get a faster machine (as recommended in the docs). We haven't tired any higher memory settings.

    We see similar behaviour to @richardowright and its important to note that the mean latency is not the only problem; some requests can still take multiple seconds even when auth is hardcoded to give a lower mean latency. Similar behaviour is seen in App Engine Flex with Node.js i.e. some requests take > 1 sec even though the mean for reads is lower ~ 600ms.

  13. lc-chrisbarton commented on Dec 14, 2017

    @lc-chrisbarton

    I just did the same test against DynamoDB using a 1024MB Lambda behind API Gateway using Go and eawsy's aws-lambda-go-shim and the latency was ~490ms and pretty stable. This is all very rough and ready but seems there is no big difference between Go/AppEngine/Datastore compared to Go/API Gateway/Lambda/DynamoDB and so once Cloud Functions gets Go support I will be happy :)

    perf-lambda-go.txt

  14. stephenplusplus commented on Dec 16, 2017

    @stephenplusplus
    Contributor

    This issue was moved to googleapis/nodejs-datastore#9.

  15. removed
    status: blocked
    on Dec 16, 2017
  16. lazharichir commented on Jan 13, 2018

    @lazharichir

    Facing the very same issue with Google Cloud Functions and Firestore... First call takes several seconds, generally from 3 to 6 seconds. Subsequent calls half the latency. I have separate Functions talking to a MongoDB VM in Compute Engine, and the latency is < 1s, except on the first call where it's around 3-5 seconds.

    I've moved some functions to AWS Lambda with DynamoDB where the latency is at most 1.5s, which is definitely doable in an end-user facing situation.... Sad.

  17. lc-chrisbarton commented on Jan 13, 2018

    @lc-chrisbarton

    @lazharichir you should probably add your comment here googleapis/nodejs-datastore#9 since this issue is closed

  18. lc-chrisbarton commented on Jan 13, 2018

    @lc-chrisbarton

    @lazharichir you can significantly improve latency in AWS Lambda if you use a CloudWatch scheduled Lambda to keep your function warm

  19. koistya commented on Feb 26, 2018

    @koistya
    Contributor

    So far I have ~500ms latency for a simple API request. Do you have a suggestion how to trace it and find the cause of the issue? Or, is it totally normal for Cloud Functions to have such latency?

    https://firebase.reactstarter.com online demo + source code

  20. karlbateman commented on May 11, 2018

    @karlbateman

    Can someone confirm whether or not using gRPC makes a notable difference?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: datastorecore

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions