OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.13k stars 572 forks source link

BETA BLOG - Instant Support for HTTP Session Cache in Liberty 24.0.0.6 #28337

Open anjumfatima90 opened 2 weeks ago

anjumfatima90 commented 2 weeks ago

The information you provide here will be included in the Open Liberty beta blog post (example), which will be published on openliberty.io/blog/, and potentially elsewhere, to promote this beta feature/function of Open Liberty. For this post to be included in the beta issue please make sure that this is completed by the end of Friday following the GM (Tuesday). The beta and release blogs are created using automation and rely on you following the template's structure. DO NOT REMOVE/ALTER THE <GHA> TAGS THROUGHOUT THIS TEMPLATE.

Please provide the following information: ​

  1. Which Liberty feature(s) does your update relate to?

    Human-readable name (eg WebSockets feature): JCache Session Persistence

    Short feature name (eg websockets-1.0): sessionCache-1.0

  2. Who is the target persona? Who do you expect to use the update? eg application developer, operations.
    Application Developer

  3. Provide a summary of the update, including the following points:

    • A sentence or two that introduces the update to someone new to the general technology/concept.

    • What was the problem before and how does your update make their life better? (Why should they care?)

    • Briefly explain how to make your update work. Include screenshots, diagrams, and/or code snippets, and provide a server.xml snippet.

    • Where can they find out more about this specific update (eg Open Liberty docs, Javadoc) and/or the wider technology?

Open Liberty InstantOn provides fast startup times for MicroProfile and Jakarta EE applications. With InstantOn, your applications can start in milliseconds, without compromising on throughput, memory, development-production parity, or Java language features. InstantOn uses the Checkpoint/Restore In Userspace (CRIU) feature of the Linux kernel to take a checkpoint of the JVM that can be restored later.

The Liberty Beta 24.0.0.6 provides InstantOn support for JCache Session Persistence. The sessionCache-1.0 feature uses a JCache provider to create a distributed in-memory cache. Distributed Session Caching is achieved when the server is connected to at least one other server to form a cluster. Open Liberty servers can behave in the following ways in a cluster.

  1. Client Server Model : An Open Liberty server can act as the JCache client and connect to a dedicated JCache server.
  2. Peer-to-Peer Model : An Open Liberty server can connect with other Open Liberty servers that are also running with the JCache Session Persistence feature and configured to be part of the same cluster.

To enable JCache Session Persistence, sessionCache-1.0 feature must be enabled

<feature>sessionCache-1.0</feature>

The client/server mode can be configured using the below server.xml configuration.

<library id="InfinispanLib">
    <fileset dir="${shared.resource.dir}/infinispan" includes="*.jar"/>
</library>
<httpSessionCache cacheManagerRef="CacheManager"/>
<cacheManager id="CacheManager">
    <properties
        infinispan.client.hotrod.server_list="infinispan-server:11222"
        infinispan.client.hotrod.auth_username="sampleUser"
        infinispan.client.hotrod.auth_password="samplePassword"
        infinispan.client.hotrod.auth_realm="default"
        infinispan.client.hotrod.sasl_mechanism="PLAIN"
        infinispan.client.hotrod.java_serial_whitelist=".*"
        infinispan.client.hotrod.marshaller=
            "org.infinispan.commons.marshall.JavaSerializationMarshaller"/>
    <cachingProvider jCacheLibraryRef="InfinispanLib" />
</cacheManager>

The peer-to-peer mode can be configured using the following server.xml configuration.

<library id="JCacheLib">
    <file name="${shared.resource.dir}/hazelcast/hazelcast.jar"/>
</library>

<httpSessionCache cacheManagerRef="CacheManager"/>

<cacheManager id="CacheManager" >
    <cachingProvider jCacheLibraryRef="JCacheLib" />
</cacheManager>

Note: In order to provide InstantOn support for peer-to-peer mode using Infinispan as a JCache Provider, Infinispan 12 and above must be used. Additionally, MicroProfile Reactive Streams 3.0 and above, and MicroProfile Metrics 4.0 and above features must be enabled inside server.xml in addition to the JCache session persistence feature.

Vendor-specific JCache configuration properties can be provided by the environment when the server is restored from the checkpoint. The following configuration uses server list, username and password values as variables defined in the restore environment.

<httpSessionCache libraryRef="InfinispanLib">
    <properties infinispan.client.hotrod.server_list="${INF_SERVERLIST}"/>
    <properties infinispan.client.hotrod.auth_username="${INF_USERNAME}"/> 
    <properties infinispan.client.hotrod.auth_password="${INF_PASSWORD}"/> 
    <properties infinispan.client.hotrod.auth_realm="default"/>
    <properties infinispan.client.hotrod.sasl_mechanism="PLAIN"/>
</httpSessionCache>
</GHA-BLOG-SUMMARY>

What happens next?