1
votes

I have 2 EC2 instances running Glassfish app server (running the exact same deployed application) and these run under an Elastic Load Balancer. This is working great but I am worried about caching inconsistencies with the EJBs.

Situation: Client sends request to ELB which forwards to EC2 instance 1. Some EJB object, let's call it EJB1, gets cached. Client --> ELB --> EC2-1 (EJB1 cached)

A short time later Client sends another request but this gets forwarded now to EC2 instance 2. EJB1 now is cached on that instance. Client --> ELB --> EC2-2 (EJB1 cached)

A short time later Client sends another request and is forwarded to EC2 instance 1. EJB1 is still in cache but is not up to date, thus causing a cache inconsistency. Client --> ELB --> EC2-1 (EJB1 cached)

Unfortunately I haven't been able to actually see this issue yet but I feel that it's a possibility. Other than turning caching of EJBs off, what is the proper way to prevent this from happening?

Thanks.

2

2 Answers

1
votes

Amazon provides "session stickiness" support at the load balancer. This means, assuming the user has cookies enabled, they are sent to the same EC2 instance for the lifetime of their session.

1
votes

Until you implement a level 2 cache your instances are not going to share the cache.

Here are a couple of links for level 2 caching solutions. (open source) http://www.terracotta.org/ehcache/ (lots of cash) http://www.oracle.com/technetwork/middleware/coherence/overview/index.html