Re: FW: Question regarding backend connection rates

2021-11-22 Thread Willy Tarreau
Hi Dominik,

On Mon, Nov 22, 2021 at 10:31:15AM +, Froehlich, Dominik wrote:
> For ongoing connections (not total), the stats page shows a tooltip stating
> 
> 
>   *   Current Active Connections
>   *   Current Used Connections
>   *   Current Idle Connections (broken down into safe and unsafe idle 
> connections)
> 
> What is the difference between active and used connections? Which number
> combined with idle connections reflects the current number of open
> connections on the OS level? (i.e. using resources like fds, buffers, ports)

You had me look at the code to figure the exact detail :-/

They're not computed the same way but I think that this results in them
being equivalent nowadays:
  - active is server->cur_sess, which is incremented whenever we need to
establish a connection to a server, possibly after leaving the queue;

  - used is the number of server connections used, that is maintained at
the idle pool layer for statistics.

Functionally speaking, even though they are not computed at the same place
and for the same reasons, I think they're the same. And except in rare
cases in my tests (slight timing differences), I think they're the same
now. Previously when idle connections couldn't be shared between threads
it would have been more complicated as one would be a sum of stuff that
could not necessarily be usable though. That's probably something we need
to consider cleaning for future versions.

> My ultimate goal is to answer the question "how loaded is this machine?" vs.
> a limit of open connections.

Got it. Then use either (or focus on active which is the historical one).
It's incremented only when under use. And use "used+idle" to know the number
of established connections at the OS level.

> What's the difference between safe and unsafe idle connections? Is it related
> to the http-reuse directive, e.g. private vs. non-private reusable
> connections?

Yes that's in part it. A safe connection is one which has proven that it was
reusable (it got reused at least once) an on which we're OK with sending the
first request of a connection because it's reasonably safe. An unsafe
connection is one that has processed 0 or 1 request only. When you use
"http-reuse always", this makesk no difference, both are always used.

Willy



Re: FW: Question regarding backend connection rates

2021-11-22 Thread Froehlich, Dominik
Hi Willy,

Thanks for the response, yes I think that clarifies the rates for me.

I have another question you probably could help me with:

For ongoing connections (not total), the stats page shows a tooltip stating


  *   Current Active Connections
  *   Current Used Connections
  *   Current Idle Connections (broken down into safe and unsafe idle 
connections)

What is the difference between active and used connections? Which number 
combined with idle connections reflects the current number of open connections 
on the OS level? (i.e. using resources like fds, buffers, ports)
My ultimate goal is to answer the question “how loaded is this machine?” vs. a 
limit of open connections.

What’s the difference between safe and unsafe idle connections? Is it related 
to the http-reuse directive, e.g. private vs. non-private reusable connections?

Thank you so much,
D

From: Willy Tarreau 
Date: Saturday, 20. November 2021 at 10:01
To: Froehlich, Dominik 
Cc: haproxy@formilux.org 
Subject: Re: FW: Question regarding backend connection rates
Hi Dominik,

On Fri, Nov 19, 2021 at 08:42:40AM +, Froehlich, Dominik wrote:
> However, the number of "current sessions" at the backend is almost 0 all the
> time (between 0 and 5, the number of servers). When I look at the "total
> sessions" at the backend after the test, it tells me that 99% of connections
> have been reused. So in my book, when a connection is reused no new
> connection needs to be opened, that's why I am so stumped about the backend
> session rate. If 99% of sessions are reused, why is the rate of new sessions
> not 0?

This is because the "sessions" counter indicates the number of sessions
that used this backend. Sessions are idle in the frontend waiting for a
new request, and once the request is analysed by the frontend rules, it's
routed to a backend, at which point the counter is incremented. As such,
in a backend you'll essentially see as many sessions as requests.

The "new connections" counter, that was added after keep-alive support
was introduced many years ago will, however, indicate the real number of
new connections that had to be established to servers. And this is the
same for each "server" line by the way.

I've sometimes been wondering whether it could make sense to change the
"sessions/total" column in the stats page to show the number of new
connections instead, but it seems to me that it would not bring much
value and will only result in causing confusion to existing users. Given
that in both cases one will have to hover on the field to get the details,
it would not help I guess.

Hoping this helps,
Willy