You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Daniel Andres Pelaez Lopez <es...@gmail.com> on 2023/11/28 20:23:20 UTC

Tracking keep alive connections

Hi community,

We have a heavy workload where the client uses a lot of keep-alive
connections, and we want to measure how many keep-alive connections
are open, but we cannot find metrics (MBean) with that information.
The closest one is tomcat_connections_keepalive_current but it seems
weird the data doesn't match, and tomcat_connections_current counts
everything.

From this old post
(https://users.tomcat.apache.narkive.com/LbyzmDXn/how-to-get-the-number-of-keep-alive-connections),
it seems hard to measure it, so, do we have any other metrics that can
help? like tomcat_connections_closed or similar? maybe by knowing the
closed ones vs open ones, we can figure out the keep-alive ones.

Any insight will be appreciated.

-- 
Daniel Andrés Pelaez López

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tracking keep alive connections

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Daniel,

On 12/1/23 00:09, Daniel Andres Pelaez Lopez wrote:
> Christopher,
> 
> So... when a connection is established, save the current timestamp on
>> the connection. When it closes, take the delta of the
>> start-of-connection and end-of-connection, and add it to a bounded queue
>> (say, 100? 1000?) of most-recent-connection-lifetimes. Any time you
>> request the average from the bean, it does the math on the whole set?
>>
> 
> That makes totally sense, any way to listen those events in Tomcat?

Not really. It's probably something that would have to be implemented 
internally to Tomcat. The trick is iterating over a list of samples 
while that list is being mutated.

I was just trying to understand what you were looking for.

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tracking keep alive connections

Posted by Daniel Andres Pelaez Lopez <es...@gmail.com>.
Christopher,

So... when a connection is established, save the current timestamp on
> the connection. When it closes, take the delta of the
> start-of-connection and end-of-connection, and add it to a bounded queue
> (say, 100? 1000?) of most-recent-connection-lifetimes. Any time you
> request the average from the bean, it does the math on the whole set?
>

That makes totally sense, any way to listen those events in Tomcat?

>

Re: Tracking keep alive connections

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Daniel,

On 11/30/23 07:08, Daniel Andres Pelaez Lopez wrote:
>> What kind of number are you looking for?
> 
> I would say something like the time a connection has been open.
> 
>> Can you please give the JMX path to tomcat_connections_keepalive_current
>> and tomcat_connections_current? I have no idea what you are talking
>> about there... is there some tool that provides those "variable names"
>> to you somewhere?
> 
> Those are metrics generated when we activate
> server.tomcat.mbeanregistry.enabled=true in Spring Boot
> 
>> By definition, any connection that is open and not currently-processing
>> a request is in the "keep-alive" state. Is that what you want to count?
>> The Manager application has a view of all current connections which
>> shows their state, including "waiting for next keep-alive request".
> 
> Understand, I think the connection time is what I searching for, for
> instance, if the average connection time is 1 hour for 50 connections,
> with a keep alive timeout of 5 minutes, it means the connection was
> receiving requests the whole hour.

So... when a connection is established, save the current timestamp on 
the connection. When it closes, take the delta of the 
start-of-connection and end-of-connection, and add it to a bounded queue 
(say, 100? 1000?) of most-recent-connection-lifetimes. Any time you 
request the average from the bean, it does the math on the whole set?

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tracking keep alive connections

Posted by Daniel Andres Pelaez Lopez <es...@gmail.com>.
> What kind of number are you looking for?

I would say something like the time a connection has been open.

> Can you please give the JMX path to tomcat_connections_keepalive_current
> and tomcat_connections_current? I have no idea what you are talking
> about there... is there some tool that provides those "variable names"
> to you somewhere?

Those are metrics generated when we activate
server.tomcat.mbeanregistry.enabled=true in Spring Boot

> By definition, any connection that is open and not currently-processing
> a request is in the "keep-alive" state. Is that what you want to count?
> The Manager application has a view of all current connections which
> shows their state, including "waiting for next keep-alive request".

Understand, I think the connection time is what I searching for, for
instance, if the average connection time is 1 hour for 50 connections,
with a keep alive timeout of 5 minutes, it means the connection was
receiving requests the whole hour.

-- 
Daniel Andrés Pelaez López

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tracking keep alive connections

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Daniel,

On 11/28/23 15:23, Daniel Andres Pelaez Lopez wrote:
> Hi community,
> 
> We have a heavy workload where the client uses a lot of keep-alive
> connections, and we want to measure how many keep-alive connections
> are open, but we cannot find metrics (MBean) with that information.
> The closest one is tomcat_connections_keepalive_current but it seems
> weird the data doesn't match, and tomcat_connections_current counts
> everything.
> 
>  From this old post
> (https://users.tomcat.apache.narkive.com/LbyzmDXn/how-to-get-the-number-of-keep-alive-connections),
> it seems hard to measure it, so, do we have any other metrics that can
> help? like tomcat_connections_closed or similar? maybe by knowing the
> closed ones vs open ones, we can figure out the keep-alive ones.
> 
> Any insight will be appreciated.

What kind of number are you looking for?

The total number of connections should increase by 1 every time a new 
connection is established -- that seems obvious.

Can you please give the JMX path to tomcat_connections_keepalive_current 
and tomcat_connections_current? I have no idea what you are talking 
about there... is there some tool that provides those "variable names" 
to you somewhere?

This other number... should that be the total number of requests ever 
requested? I think that already exists 
(GloablRequestProcessor/[connector]/requestCount or 
WebModule/[app]/none/none/requestCount).

So the average number of keep-alives-per-connection would just be the 
ratio of those two. But it sounds like you'd like to get the 
current-number of keep-alive requests for any active connection at any 
time. Is that what you are asking?

"Give me the maximum number of keep-alive requests for any current 
connections?"

Answer: a single integer

"Give me the average number of keep-alive requests for all current 
connections?"

Answer: a single integer

"Give me all the keep-alives for currently-active connections?"

Answer: a list of up to 10,000 integers (by default, can be increased 
via configuration)

By definition, any connection that is open and not currently-processing 
a request is in the "keep-alive" state. Is that what you want to count? 
The Manager application has a view of all current connections which 
shows their state, including "waiting for next keep-alive request".

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org