question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance hit with sequalize on lambda?

See original GitHub issue

I am you performance issues with (i believe) sequalize on lambda and am wondering if this is just the norm. For example, I have a call where my app thinks the timing is 97 mc but lambda actually takes 1102 ms. The timings of my test lambda without sequalize seem to make more sense. Anyways, any thoughts are appreciated.

// my pool

pool: {
max: 1,
min: 0,
idle: 100

},

// snippet

module.exports.handler = function (event, context, cb) {
  console.time("reqstart")
  var model = require('../models');
  var group;
    model.Group.create({})
  .then(function (localGroup) {
    console.timeEnd("reqstart")
    return cb(null, {
      message: 'Go Serverless! Your Lambda function executed successfully! '+JSON.stringify(event, null, 2)
   });
})
.catch(function (err) {
  console.log(err);      
});

};

// cloudwatch logs

START RequestId: 7384364a-2b93-11e6-9d8f-83d013cc53d6 Version: 60  
2016-06-06T03:04:59.120Z    undefined   Executed (default): INSERT INTO "Groups"  ("id","createdAt","updatedAt") VALUES ('54d96b10-7e24-4c0b-ac26-6f2444f65978','2016-06-06 03:04:59.030 +00:00','2016-06-06 03:04:59.030 +00:00') RETURNING *; 10 
2016-06-06T03:04:59.123Z    7384364a-2b93-11e6-9d8f-83d013cc53d6    reqstart: 97ms
END RequestId: 7384364a-2b93-11e6-9d8f-83d013cc53d6 
REPORT RequestId: 7384364a-2b93-11e6-9d8f-83d013cc53d6  Duration: 1102.49 ms               Billed Duration: 1200 ms Memory Size: 1024 MB    Max Memory Used: 41 MB

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

69reactions
atwoodjwcommented, Jun 15, 2016

Found the issue after RTFM.

http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html#nodejs-prog-model-context-properties

You have to set context.callbackWaitsForEmptyEventLoop = false. Otherwise, the process isn’t terminated until the event loop is empty.

Hope this helps someone.

5reactions
marlomgirardicommented, May 30, 2018

Unfortunately, Sequelize is not good for lambda because the higher cost is the startup…

With sequelize it takes almost 1s to return the request and with mysql2 in most cases lower than 100ms.

2018-05-30T15:42:11.370Z	04395f47-6420-11e8-9c1a-95b27db38b01	DBREQUEST: 141.998ms
2018-05-30T15:42:11.371Z	04395f47-6420-11e8-9c1a-95b27db38b01	REQUESTEND: 622.803ms
END RequestId: 04395f47-6420-11e8-9c1a-95b27db38b01
REPORT RequestId: 04395f47-6420-11e8-9c1a-95b27db38b01	Duration: 623.37 ms	Billed Duration: 700 ms Memory Size: 128 MB	Max Memory Used: 48 MB	
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using sequelize in AWS Lambda
AWS Lambda is a serverless computing service that allows customers. ... re-use the sequelize instance across invocations to improve performance
Read more >
AWS Lambda vs Sequelize | What are the differences?
AWS Lambda - Automatically run code in response to modifications to objects in Amazon S3 buckets, messages in Kinesis streams, or updates in...
Read more >
Hijacking Sequelize with Fyresite's MySQL Data API Wrapper
When the Lambda's already warm, Sequelize mitigates some of these performance issues by reusing connections with pools.
Read more >
A crash course on Serverless with AWS - Building APIs ...
I have a serverless project integrated with express and sequelize, such that a single lambda has multiple routes. The F.E calls 6 api...
Read more >
Sequelize Code Not Executing Inside AWS Lambda
Yesterday found that if you're using callback(null, successData), the performance was really poor (>11 secs on a Select top 1). Had to change ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found