waterye

          memcached java client

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

          a. 使用whalin版會導致File Descriptor leak,而使用spy版則不會,原因是whalin版沒有使用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);
          通過lsof -p pid | grep pipe可以觀察是否有fd leak.

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

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

          Feedback

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

          與用不用selector來管理無關,倒是close沒調是真的!  回復  更多評論   

          # re: memcached java client[未登錄] 2009-12-27 01:12 waterye

          @laurence 用s版很久了,系統很穩定,沒有去理w版了
            回復  更多評論   

          主站蜘蛛池模板: 合阳县| 德钦县| 项城市| 德清县| 政和县| 雷州市| 且末县| 华阴市| 建湖县| 琼结县| 抚顺县| 渑池县| 屯门区| 滦南县| 乌拉特中旗| 宽城| 祁连县| 阳泉市| 乌兰察布市| 宣汉县| 个旧市| 波密县| 察雅县| 乐业县| 汤原县| 乌什县| 兴仁县| 全州县| 巴彦县| 阳曲县| 大方县| 莱阳市| 镇巴县| 浮梁县| 永胜县| 昔阳县| 诏安县| 南乐县| 临洮县| 芮城县| 葫芦岛市|