Servlet session attribute size and lifetime

1) What is the acceptable range of sizes of objects that should be attached to the session? If I attach an object that can be 5k, and I have 10k valid sessions at any given time, then 50MB of memory, which seems acceptable to me. Is this really suitable for solving this problem or are there other significant issues?

2) This is probably a stupid question, but if I attach an object to a session with a 2-week life cycle, can I access the attribute as if it had been in memory for the entire session?

3) Is there any reason NOT to always save session information in the database?

+4
source share
2 answers
  • The allowable size depends on your use case and the number of concurrent sessions. If your sessions last 2 weeks, then we can assume that you can have many simultaneous sessions, but if 10k is your maximum maximum, then there should be no problems with a 5k session object (as your calculation shows).

  • As long as you reference the session object (or you can get such a link), the data will be stored in the session. Remember that your session objects must be serialized.

  • You may not want to save all session data in db for performance reasons, especially if session data can be easily recreated.

+3
source
  • Java EE does not limit the size of an HTTP session. The RAM requirements for your web application will be x + su * s, where "x" is the rest, "su" is the maximum number of concurrent session users, and "s" is the size of the session object. So, if this is an application with no more than 5 users, go to it. If it has 1,500 users, you can review. The time required to serialize / deserialize each session object will increase more or less linearly with the size of the object. Therefore, if many consecutive conversions are expected, be prepared.
  • You can while your session is alive.
  • Persist sesion data is expensive in performance, you should only do this when you need session replication in a cluster for recovery.
+3
source

Source: https://habr.com/ru/post/1399868/


All Articles