High memory utilisation on postgres

17 views
Skip to first unread message

Imran Bohoran

unread,
Oct 31, 2016, 5:41:02 AM10/31/16
to Sequelize
Hello

I've got a question that I was hoping I could get some help in clarifying.

I've got a node app, that manages sessions using express-session. The sessions are stored in postgres, and hence we are using the 'connect-session-sequelize' module to store/retrieve session data, which sits in the middle of express and sequelize.
So I've hit this issue where memory consumption of the postgres database keeps increasing and once its gone over the swap limit the database crashes.

The reason this seem to be happening is because the usage of the 'findOrCreate' function by the connect-session-sequelize module. The reason for this assertion is because, I can reproduce the scenario with a simple express app, using the 'findOrCreate' function. If I use the 'create' function that doesn't happen under the same load. I realise that there are transactions involved in 'findOrCreate' that is not included in the 'create' function. However, another difference I see between those functions is the creation of the temporary function that is wrapping the insert statement. Specifically I'm referring to - https://github.com/sequelize/sequelize/blob/master/lib/dialects/abstract/query-generator.js#L153.

I was hoping if someone could provide some details around the reasoning for the temporary function, which was seemed to have been introduced couple of years ago - https://github.com/sequelize/sequelize/blob/70e053cbb8e66ef6c21091cc1b3d8ab46ae1325e/lib/dialects/abstract/query-generator.js#L158

Please note that this only seems to be happening if a resource using this function is called at a high rate. The memory usage only ever seem to go down if the node app is killed. I've also checked that there aren't any connection leaks. Any insights on this problem is greatly appreciated. Thanks.

Cheers
-- Imran
Reply all
Reply to author
Forward
0 new messages