dev@grizzly.java.net

Re: A question about outbound connection cache

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Fri, 20 Feb 2009 11:15:41 +0100

Hi Monoru,

you were right, there was really issue with returning
CacheableConnectorHandler back to pool. Because at the same time
connection may be used by OutboundConnectionCache.
But there is also problem in your test - you can not start send UDP
packets in loop, before making sure, that Controller has started.
For example like this:

         final CountDownLatch latch = new CountDownLatch(1);
         controller.addStateListener(new
ControllerStateListenerAdapter() {
             @Override
             public void onReady() {
                 latch.countDown();
             }

             @Override
             public void onException(Throwable e) {
                 if (latch.getCount() > 0) {
                     Controller.logger().log(Level.SEVERE, "Exception
during " +
                             "starting the controller", e);
                     latch.countDown();
                 } else {
                     Controller.logger().log(Level.SEVERE, "Exception
during " +
                             "controller processing", e);
                 }
             }
         });

         new Thread(controller).start();

         try {
             latch.await();
         } catch (InterruptedException ex) {
         }

WBR,
Alexey.


On Feb 20, 2009, at 1:31 , Minoru Nitta wrote:

> Hi Alexey,
>
>
> Thank you for your concern. I tried your suggestion and here is the
> result.
> Before I tried your modification, I modified my test program a bit.
> I modified
> TestFilter.execute as follows, to simulate more real world.
>
> int number = counter % 4;
> if (number == 0)
> destination = new InetSocketAddress(InetAddress.getLocalHost(),
> 5063);
> else if (number == 1)
> destination = new InetSocketAddress(InetAddress.getLocalHost(),
> 5064);
> else if (number == 2)
> destination = new InetSocketAddress(InetAddress.getLocalHost(),
> 5065);
> else if (number == 3)
> destination = new InetSocketAddress(InetAddress.getLocalHost(),
> 5066);
> counter++;
>
> In addition to that, I changed the highest watermark to 100.
>
> In main(), I tried the following code.
>
> for (int i = 0; i < 20; i++){
> DatagramPacket packet = new DatagramPacket(data, 0,
> data.length, local,5060);
> socket.send(packet);
> Thread.sleep(1 * 1000);
> socket.send(packet);
> Thread.sleep(1 * 1000);
> socket.send(packet);
> Thread.sleep(1 * 1000);
> }
>
> The result is as follows.
>
> [root_at_rx200-3 ~]# netstat -a -u
> Active Internet connections (servers and established)
> Proto Recv-Q Send-Q Local Address Foreign
> Address State
> udp 0 0 *:2727 *:*
> udp 0 0 *:4520 *:*
> udp 0 0 *:836 *:*
> udp 0 0 *:839 *:*
> udp 0 0 *:5065 *:*
> udp 0 0 *:4569 *:*
> udp 0 0 *:sunrpc *:*
> udp 0 0 *:ipp *:*
> udp 0 0 rx200-3:ntp *:*
> udp 0 0 localhost.localdomain:ntp *:*
> udp 0 0 *:ntp *:*
> udp 0 0 rx200-3:32806
> rx200-3:5063 ESTABLISHED
> udp 0 0 rx200-3:32809
> rx200-3:5064 ESTABLISHED
> udp 0 0 rx200-3:32810
> rx200-3:5065 ESTABLISHED
> udp 0 0 rx200-3:32811
> rx200-3:5066 ESTABLISHED
> udp 0 0 *:5060 *:*
> udp 0 0 *:5062 *:*
> udp 0 0 *:ntp *:*
>
>
> The aboeve is exactly the same as what I expected. Then, I removed
> 'Thread.sleep' from main(), as follows.
>
> for (int i = 0; i < 20; i++){
> DatagramPacket packet = new DatagramPacket(data, 0,
> data.length, local,5060);
> socket.send(packet);
> socket.send(packet);
> socket.send(packet);
> }
>
> The result is below.
>
> [root_at_rx200-3 ~]# netstat -a -u
> Active Internet connections (servers and established)
> Proto Recv-Q Send-Q Local Address Foreign
> Address State
> udp 0 0 *:2727 *:*
> udp 0 0 *:4520 *:*
> udp 0 0 *:836 *:*
> udp 0 0 *:839 *:*
> udp 0 0 *:5065 *:*
> udp 0 0 *:4569 *:*
> udp 0 0 *:sunrpc *:*
> udp 0 0 *:ipp *:*
> udp 0 0 rx200-3:ntp *:*
> udp 0 0 localhost.localdomain:ntp *:*
> udp 0 0 *:ntp *:*
> udp 0 0 *:5060 *:*
> udp 0 0 *:5062 *:*
> udp 0 0 *:ntp *:*
>
> I do not know why, but there is no connection to port 5063, 5064,
> 5065 and 5066.
> I am wondering why two results are different. I thought that two
> results should be same.
>
>
> Minoru
>
>> Hi Minoru,
>>
>> please try this fix in your code to check if it works:
>>
>> try {
>> connectorHandler.write(buffer, false);
>> } catch (Exception e) {
>> } finally {
>> /*FIX ---> */ connectorHandler.close();
>> }
>>
>>
>> Thanks.
>>
>> WBR,
>> Alexey.
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net
>