We are looking to externalize/cache HttpSessions exactly for the reason when the application crash/restart that it is seamless to the client.
From the documentation that I’ve read, the out-of-the-box HttpSession externalization to Infinispan, required that the application instances must be in a cluster.
Our application instances are deployed as standalone. Will it still be possible to use the out-of-the-box solution?
We are looking at using Redis as the external HttpSession store. I cannot find an easy way to plugin Redis. Seems you have to implement (override) ServletExtension, SessionManagerFactory and SessionManager?
Thank you for the information, it's very helpful.
Our applications are WildFly Bootable Jars (WF 24.0.1.Final).
We have a load balancer (AVI/HAProxy) in front of the applications for load balancing, high availability and where necessary, sticky sessions.
Typically an application will have 1 or more instances running on 2+ nodes.
For Example:
Application_A (instance 1 port 9080) runs on Server_1 (node1) and on Server_2 (node2),
Application_A (instance 2 port 9081) runs on Server_1 (node1) and on Server_2 (node2),
Application_B (instance 1 port 8087) runs on Server_1 (node1) and on Server_2 (node2),
Application_C (instance 1 port 8090) runs on Server_3 (node3) and on Server_4 (node4),
Application_C (instance 2 port 8091) runs on Server_3 (node3) and on Server_4 (node4),
Application_C (instance 3 port 8092) runs on Server_3 (node3) and on Server_4 (node4),
Application_C (instance 4 port 8093) runs on Server_3 (node3) and on Server_4 (node4)
So option 1 and 5 is not applicable.
The applications where we want to externalize Http Session, are high volume/high concurrency applications and what we store on Http Session can be updated often during a request.
So it looks as if option 2 is not viable either.
At the moment we are doing research on your option 4.
(Side note - I don't feel that ambitious)
We will definitely have more questions on this journey and will ask questions as they arise. Thanks!
Within a WildFly bootable app (WildFly 24.0.1.Final), which property takes precedence? The hotrod properties or the infinispan/remote-cache-container?For example:subsystem=infinispan/remote-cache-container/statistics-enabled's default value is falseininispan.client.hotrod.statistics default value is ENABLED
subsystem=infinispan/remote-cache-container/ component=connection-pool's max-wait and max-active don't have default valuesinfinispan.client.hotrod.connection_pool.max_active and max_wait's deault value is -1
First request to application instance 1:
If the user object is null on HttpSession, creates it and adds it to HttpSession
Second request to instance 2
Gets the user object and updates a timestamp on it
Third request to instance 1
Gets the user object and updates a timestamp on it
While testing a simple implementation or option 4, I have a few questions.WildFly 24.0.1.Final
Bootable jar 5.0.2.Final
2 application instances / AVI loadbalancer
1 infinispan server
Configurations:granularity="SESSION"
no-affinity
default-session-timeout="6"
web.xml: <distributable/>
Rest of the configurations – default (I haven't enabled near cache, to my knowledge it is then disabled)
I've enabled HotRod logging in the applicationFirst request to application instance 1:
If the user object is null on HttpSession, creates it and adds it to HttpSession
The logs that I see, that is before it communicates to the Infinispan Server to add the session to Infinispan serveer's cache?
- About to add (K,V): (SessionCreationMetaDataKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI), SimpleSessionCreationMetaData{created=2022-08-12T08:56:17.019Z, max-inactive-interval=PT0S})
- About to add (K,V): (SessionAccessMetaDataKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI), SimpleSessionAccessMetaData{since-creation=PT0Slast-access=PT0S})
- About to add (K,V): (SessionAttributesKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI), {})
- About to add (K,V): (SessionCreationMetaDataKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI), SimpleSessionCreationMetaData{created=2022-08-12T08:56:17.019Z, max-inactive-interval=PT6M})
- About to add (K,V): (SessionAccessMetaDataKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI), SimpleSessionAccessMetaData{since-creation=PT0Slast-access=PT1S})
- About to add (K,V): (SessionAttributesKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI), {user=za.co.session.hotrod.User@69875b13})
- Infinispan Admin Console: Stores = 6
So looking at the above logs it corresponds to the forum discussion https://groups.google.com/d/msgid/wildfly/91ec9beb-c46c-447e-9ecc-f26273d2b275n%40googlegroups.com that 3 cache entries are created in Infinispan server for the HttpSessionThe Stores=6 statistic in the console, I assume means that there was 6 calls to the server to add or update cache entries. Is there anything that indicates the number of HttpSessions cached in the Infinispan server?
In the application instance, does WildFly store the HttpSession in memory for the duration of the request?
Second request to instance 2
Gets the user object and updates a timestamp on it
- About to getAll entries ([SessionCreationMetaDataKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI), SessionAccessMetaDataKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI)])
- About to add (K,V): (SessionAccessMetaDataKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI), SimpleSessionAccessMetaData{since-creation=PT42.952Slast-access=PT1S})
- About to add (K,V): (SessionAttributesKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI), {user=za.co.session.hotrod.User@4dce4a64})
- Infinispan Admin Console: Hits=3 Stores=8 Retrievals=3
In this instance it will fetch the session information from the Infinispan server, then after the change to the UserObject it will update the cache entries on the Infinnispan server for the session.
Third request to instance 1
Gets the user object and updates a timestamp on it
- About to getAll entries ([SessionAccessMetaDataKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI), SessionCreationMetaDataKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI)])
- About to add (K,V): (SessionAccessMetaDataKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI), SimpleSessionAccessMetaData{since-creation=PT1M46.85Slast-access=PT1S})
- About to add (K,V): (SessionAttributesKey(Ac-3z6Ibg-oAQEPlXcGXKGlpkDariI03JniyzFSI), {user=za.co.session.hotrod.User@776136ee})
- Infinispan Admin Console: Hits=6 Stores=10 Retrievals=3
In this instance it will fetch the session information from the Infinispan server, then after the change to the UserObject it will update the cache entries on the Infinnispan server for the session.No more requests to any of the application instances until the session times out.I assume the container communicates the session timeout and HotRod will now communicate to Ininispan Server that the session expired ? This happens in both the application instances as far as I can see (?) but it will not try and delete the session stored on Infinispan server twice, only once?
The Infinispan Admin Console shows the following: Infinispan Admin Console: Hits=7 Stores=10 Retrievals = 7 Remove Hits = 3 Remove misses = 1. Is the remove misses because the session was already removed by one of the application instances and the 2nd instance couldn't remove it? And the remove hits = 3, that is equal to the 3 entries of the 1 session?
In the following scenarios, what happens to the session entries on the Infinspan server?Scenario 1: First request went to application instance 1. No more requests after the first one. For some (funny) reason someone shuts down application instance 1 before the session times out.
Scenario 2: First request went to application instance 1. No more requests after the first one. Application instance 1 crashes.