On 4/1/21 7:05 PM, Jerry Malcolm wrote:
I am running several clustered Tomcat EC2 instances in an Amazon
autoscaling group. These instances come and go based on load and
failure/restart. IP addresses are assigned dynamically. As far I can
figure, the only determinable difference between the instances is the
IP address that is assigned to each EC2 when it spins up.
I'm seeing some really weird symptoms at times that seem to indicate
that the load balancer is not always honoring session affinity. It
appears that another server periodically gets sent a request for a
session that is being handled by a different EC2. The load balancer
problem, if it exists, is definitely not a tomcat problem. However,
in order to figure out what is really happening, I need to be able to
track and differentiate which server is handling each request. Inside
my TC webapp, if I could determine programatically some unique
identifier for the EC2 running that http request, I could include that
in my logs.
My question is, is there a way to determine "my own" IP address from
within a webapp servlet? Or is there some other way that I can log
some string or some value that will guarantee to be unique within each
instance of Tomcat? I guess another option would be to somehow get
the tomcat bootup timestamp (from within a servlet) assuming two EC2s
won't boot at precisely the same instant. But I don't know a way to
access the boot timestamp. Am I missing something more obvious?
You can get this from the getLocalAddr method of the ServletRequest
object passed to your servlet's doPost/doGet. See [1].
Phil
https://javaee.github.io/javaee-spec/javadocs/javax/servlet/ServletRequest.html#getLocalAddr
Thx
Jerry
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org