• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • php一致性hash性能測試(flexihash/memcache/memcached)

    發表于:2011-02-09來源:作者:點擊數: 標簽:
    php一致性hash 性能測試 (flexihash/memcache/memcached) 一致性hash的使用在 PHP 中有三種選擇分別是原生的memcache擴展,memcached擴展,還有一個是網上比較流行的flexihash類。 最近有項目需要使用flexihash類操作memcacheq,想看看,單純使用php的flexih

      php一致性hash性能測試(flexihash/memcache/memcached)

      一致性hash的使用在PHP中有三種選擇分別是原生的memcache擴展,memcached擴展,還有一個是網上比較流行的flexihash類。

      最近有項目需要使用flexihash類操作memcacheq,想看看,單純使用php的flexihash一致性hash,分布均勻程度,性能差多少。

      php一致性hash類下載地址:http://code.google.com/p/flexihash/

      測試環境:I7 四核 LINUX FEDORA 使用linux英文詞庫作為測試用例 memcached開啟4個線程

      測試結果:

      其中,單節點指的是,在只有一個節點工作情況下的,測試結果。

      小結

      如上所示,就memcache擴展與memcached擴展比較來看,在當全部節點工作正常的時候,測試條件memcached略快,但基本可以忽略不計。當只有單節點正常工作的時候,memcached擴展性能比 memcache快,我想可能是因為,memcached擴展在檢測到連接無效的時候,沒有再進行連接測試,直接將數據hash到連接有效的節點。當然這個只是猜測,需要看源碼才能理解。

      48萬條數據操作,使用flexihash做一致性hash與使用擴展一致性hash,在hash這個過程中,速度仍舊在一個數量級上,大約是使用擴展速度的一半,其效率可以接受。在分布均勻性上,兩個擴展分布基本比較均勻,在使用flexihash不使用虛擬節點時候,分布非常不均勻,在使用16個虛擬節點后,分布均勻性已經接近擴展了。在使用虛擬節點后, set速度相比較沒使用時候略慢,get操作反而變快。

      下面給出測試源碼

      flexihash一致性hash測試

      view source

    print?
    01 require_once 'flexihash.php';
    02 Class FMemcache
    03 {
    04   
    05     public $hash = null;
    06     public $memcache = null;
    07     public $connectPool = null;
    08   
    09     public function __construct()
    10     {
    11         $this->hash = new Flexihash();
    12     }
    13   
    14     public function addServers( $servers )
    15     {
    16         foreach ($servers as $server)
    17         {
    18             $node = $server['host'] . ':' . $server['port'];
    19             $this->connectPool[$node] = false;
    20             $targets[] = $node;
    21         }
    22         $this->hash->addTargets( $targets );
    23     }
    24   
    25     public function set( $key, $value )
    26     {
    27         $nodes = $this->hash->lookupList( $key, count( $this->connectPool ) );
    28         foreach ($nodes as $node)
    29         {
    30             if (!$this->connectPool[$node])
    31             {
    32                 $server = explode( ':', $node );
    33                 $this->connectPool[$node] = @memcache_connect( $server[0], $server[1] );
    34             }
    35             if ($this->connectPool[$node])
    36             {
    37                 if (memcache_set( $this->connectPool[$node], $key, $value ))
    38                 {
    39                     return true;
    40                 }
    41             }
    42         }
    43         return false;
    44     }
    45   
    46     public function get( $key )
    47     {
    48         $nodes = $this->hash->lookupList( $key, count( $this->connectPool ) );
    49         foreach ($nodes as $node)
    50         {
    51             if (!$this->connectPool[$node])
    52             {
    53                 $server = explode( ':', $node );
    54                 $this->connectPool[$node] = @memcache_connect( $server[0], $server[1] );
    55             }
    56             if ($this->connectPool[$node])
    57             {
    58                 if (memcache_get( $this->connectPool[$node], $key ))
    59                 {
    60                     return true;
    61                 }
    62             }
    63         }
    64         return false;
    65     }
    66   
    67 }

      測試代碼:

      view source

    print?
    01 require_once 'flexihash_memcache.php';
    02 require_once 'Config.php';
    03 $st = microtime( true );
    04 $mem = new FMemcache();
    05 $mem->addServers( $tt_server_pool );
    06 $wordAmount = 0;
    07 $getCount = 0;
    08 foreach ($words as $word)
    09 {
    10     if (empty( $word ))
    11     {
    12         continue;
    13     }
    14     $inc = $mem->set( $word, $word );
    15 }
    16 $et = microtime( true ) - $st;
    17 echo "time used:" . $et;

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>