waterye

          memcached java client

          1. http://www.whalin.com/memcached/ v2.0.1
          2. http://code.google.com/p/spymemcached/ v2.2

          a. 使用whalin版會(huì)導(dǎo)致File Descriptor leak,而使用spy版則不會(huì),原因是whalin版沒(méi)有使用selector管理socketchannel.
                 Thread.sleep(1000 * 30);
                  System.out.println(
          "begin");

                  Selector selector 
          = null;
                  SocketChannel channel 
          = null;
                  
          try {
                      String host 
          = "192.168.0.74";
                      
          int port = 11211;
                      
          int timeout = 1000 * 60;

                      selector 
          = Selector.open();
                      channel 
          = SocketChannel.open();
                      channel.configureBlocking(
          false);

                      channel.connect(
          new InetSocketAddress(host, port));
                      channel.register(selector, channel.validOps());

                      
          try {
                          selector.select();
                      } 
          catch (IOException e) {
                          e.printStackTrace();
                      }

                      Iterator it 
          = selector.selectedKeys().iterator();
                      
          int i = 0;
                      
          while (it.hasNext()) {
                          i
          ++;
                          System.out.println(i);
                          SelectionKey selKey 
          = (SelectionKey) it.next();
                          it.remove();

                          
          try {
                              processSelectionKey(selKey);
                          } 
          catch (IOException e) {
                              e.printStackTrace();
                              selKey.cancel();
                          }
                      }

                      System.out.println(
          "unclose");
                      Thread.sleep(
          1000 * 30);
                  } 
          catch (Exception e) {
                      e.printStackTrace();
                  } 
          finally {
                      
          if (channel != null && channel.isOpen()) {
                          
          try {
                              channel.close();
                          } 
          catch (Exception e) {
                              e.printStackTrace();
                          }
                      }
                      
          if (selector!=null) {
                          selector.close();      
          // not fd leak
                      }
                  }

                  System.out.println(
          "end");
                  Thread.sleep(
          1000 * 30 * 1);
          通過(guò)lsof -p pid | grep pipe可以觀察是否有fd leak.

          b. w版set 1000000 object 需要600s左右,s版只需150s左右

          posted on 2008-10-31 19:55 waterye 閱讀(1555) 評(píng)論(2)  編輯  收藏 所屬分類: Java

          Feedback

          # re: memcached java client 2009-12-26 23:08 laurence

          與用不用selector來(lái)管理無(wú)關(guān),倒是close沒(méi)調(diào)是真的!  回復(fù)  更多評(píng)論   

          # re: memcached java client[未登錄](méi) 2009-12-27 01:12 waterye

          @laurence 用s版很久了,系統(tǒng)很穩(wěn)定,沒(méi)有去理w版了
            回復(fù)  更多評(píng)論   

          主站蜘蛛池模板: 阿图什市| 潢川县| 平遥县| 繁峙县| 青岛市| 和龙市| 东乡县| 富源县| 秦皇岛市| 古田县| 宽城| 芜湖市| 九江县| 江西省| 通辽市| 清水河县| 黎川县| 西青区| 侯马市| 门源| 惠水县| 津市市| 东阳市| 夏河县| 梁山县| 阿拉善右旗| 额济纳旗| 和田县| 万载县| 增城市| 班玛县| 阳泉市| 铁岭市| 宁都县| 宣威市| 大理市| 澄迈县| 织金县| 延长县| 洱源县| 双桥区|