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.

`session.touch` is called on every request when `resave: false`

See original GitHub issue

Description

[PR incoming with unit tests and implementation of option - default to no change from current behavior]

session.touch is called on every request when resave: false is set.

On in-memory stores such as connect-redis this has little impact other than additional traffic.

However, on disk-backed and/or globally replicated stores the costs can be significant, such as connect-dynamodb

Example Scenario with Costs - DynamoDB Store

DynamoDB Provisioned Capacity Pricing

image
  • RCU = Read Capacity Unit
  • WCU = Write Capacity Unit
  • 60,000 RPM site / 60 seconds / minute = 1000 RPS
  • Write on Every Request
    • 1,000 RPS requires
      • 1,000 RCU x $0.00013 = $0.13 / hour = $1,138 / year
      • 1,000 WCU x $0.00065 = $0.65 / hour = $5,964 / year
      • Total = $7,102 / year
  • Write on Update or when 75% of originalMaxAge Expired
    • Assuming 1% of requests update the session or reach 75% of originalMaxAge
    • 1,000 RPS requires
      • 1,000 RCU x $0.00013 = $0.13 / hour = $1,138 / year
      • 10 WCU x $0.00065 = $0.0065 / hour = $57 / year
      • Total = $1,195
      • Savings = 83% vs Write on Every Request

Best cases for cost reduction

  • Relatively longer sessions (e.g. minutes, hours, days, months, but not seconds)
  • Session values infrequently updated

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
dougwilsoncommented, May 20, 2022

Hi @ragesoft 👋 . In your example, the query you are showing is not part of the resave feature, but rather that your store module is updating the expires column on your data store every time the session is accessed. That may be what you want, maybe not. Ideally the store would need to add an option on it’s end to allow you to control that behavior. This module just sends a signal to the store module that the session was accessed; what the store decides is the more appropriate thing to do with that signal is left up to the store module. I hope that helps.

0reactions
dougwilsoncommented, Jul 6, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

When to use saveUninitialized and resave in express-session
Uninitialised = false. It means that Your session is only Stored into your storage, when any of the Property is modified in req....
Read more >
Disable touch on certain paths #287 - expressjs/session
Hi! No, this is not a bug, as this module will touch a session any time that session is loaded by design. Whenever...
Read more >
Express session middleware
Forces a session that is “uninitialized” to be saved to the store. A session is uninitialized when it is new but not modified....
Read more >
Connect - High quality middleware for node.js - Sencha Labs
Session #touch(). Updates the .maxAge property. Typically this is not necessary to call, as the session middleware does this for you.
Read more >
express-session - Expert Data Visualization-5309
Forces a session that is "uninitialized" to be saved to the store. A session is uninitialized when it is new but not modified....
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