users@grizzly.java.net

Re: how do I get number of active tcp connections?

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Mon, 28 Jan 2008 10:08:57 -0500

Hi Peter,

Peter Speck wrote:
> Hi,
>
> I've started using Grizzly 1.7.0 and it works very well.

Thanks!

>
> I would like to get the number of current tcp connections for statistics
> (http keep-alive connections). It seems like
> SelectorThread.getKeepAliveStats().getCountConnections() returns the
> total number of connections made (over the full lifetime) and not the
> current number of open connections.
>
> Can I obtain the number of current tcp connection from the http module,
> or from lower-level parts of Grizzly?

You are using the right interface, and found a bug. From the
implementation, it seems we are missing the logic to decrease the count:

> public boolean trap(SelectionKey key){
> if ( maxKeepAliveRequests == -1) return true;
>
> Integer count = keepAliveCounts.get(key);
> if ( count == null ){
> count = 0;
> if (keepAliveStats != null) {
> keepAliveStats.incrementCountConnections();
> }
> }
>
> if ((count++) > maxKeepAliveRequests){
> if (keepAliveStats != null) {
> keepAliveStats.incrementCountRefusals();
> }
> return false;
> }
>
> keepAliveCounts.put(key, count);
> if (keepAliveStats != null) {
> keepAliveStats.incrementCountHits();
> }
>
> return true;
> }
>
>
> /**
> * Stop monitoring keep-alive request count for the given connection.
> */
> public void untrap(SelectionKey key){
> if ( maxKeepAliveRequests == -1) return;
>
> keepAliveCounts.remove(key);
> }

Inside the untrap(..), we must decrease the count. Can you file a bug here:

https://grizzly.dev.java.net/issues/

I will fix it on the trunk now (Glassfish has the same problem, so you
have found 2 bugs :-) :-))

Thanks!

-- Jeanfrancois




>
> When I log the numbers each second, I get:
> KAS: conns=10, flushes=0, hits=20, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=11, flushes=0, hits=22, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=16, flushes=0, hits=36, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=17, flushes=0, hits=38, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=19, flushes=0, hits=42, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=20, flushes=0, hits=44, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=21, flushes=0, hits=46, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=23, flushes=0, hits=52, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=24, flushes=0, hits=60, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=25, flushes=0, hits=62, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=26, flushes=0, hits=64, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=27, flushes=0, hits=66, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=28, flushes=0, hits=68, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=29, flushes=0, hits=70, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=30, flushes=0, hits=72, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=31, flushes=0, hits=74, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=32, flushes=0, hits=76, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
> KAS: conns=33, flushes=0, hits=78, refusals=0, timeouts=0,
> maxConns=8196, secTimeouts=30
>
> KeepAliveStats kas = getKeepAliveStats();
> return "KAS: conns=" + kas.getCountConnections()
> + ", flushes=" + kas.getCountFlushes()
> + ", hits=" + kas.getCountHits()
> + ", refusals=" + kas.getCountRefusals()
> + ", timeouts=" + kas.getCountTimeouts()
> + ", maxConns=" + kas.getMaxConnections()
> + ", secTimeouts=" + kas.getSecondsTimeouts() + "\n";
>
>
> Grizzly configuration for port 80
> maxThreads: 50
> minThreads: 5
> ByteBuffer size: 32768
> useDirectByteBuffer: false
> useByteBufferView: false
> maxHttpHeaderSize: 8192
> maxKeepAliveRequests: 8196
> keepAliveTimeoutInSeconds: 30
> Static File Cache enabled: false
> Stream Algorithm : com.sun.grizzly.http.algorithms.NoParsingAlgorithm
> Pipeline : com.sun.grizzly.http.LinkedListPipeline
> Round Robin Selector Algorithm enabled: false
> Round Robin Selector pool size: 0
> recycleTasks: true
> Asynchronous Request Processing enabled: false
>
> ----
> - Peter Speck
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>