摘要:和還有共享內存都是讀取內存的數據,為了測試一下到底效率誰更勝一籌,我在我的虛擬機下做了一次公平的測試。
redis和memcache還有共享內存都是讀取內存的數據,為了測試一下到底效率誰更勝一籌,我在我的Centos虛擬機下做了一次公平的測試。
測試參數
環境:Centos (配置忽略)、語言:PHP、WebServer:Nginx、測試次數:10000、字符類型及長度:字符串(1024)
準備測試
array ("id" => "4146","attacksdfdsfdsffffdffffdffffddd" => "5.45","atk_class" => "神圣級","wufang" => "4.9","def_class" => "超神級","cefang" => "4.9","mdf_class" => "超神級","hp" => "6.43","hp_class" => "神王級","dodge" => "55","dodge_class" => "SSSS","crit" => "50","crit_class" => "SSS","penetrate" => "55","penetrate_class" => "SSSS","mingzhong" => "51","hit_class" => "SSSS","anti_dizziness" => "0","anti_dizzinesssdfdsfdsfdsfdsfds_class" => "F","anti_critical" => "20","anti_critical_class" => "F","tenacity" => "0","tenacity_class" => "F", ), 2 => array ("id" => "414ddffff7","attack" => "5.45","atk_class" => "神圣級","wufang" => "4.95","def_class" => "超神級","cefang" => "4.95","mdf_class" => "超神級","hp" => "6.43","hp_class" => "神王級","dodge" => "55","dodge_class" => "SSSS","crit" => "50","crit_class" => "SSS","penetrate" => "55","penetrate_class" => "SSSS","mingzhong" => "51","hit_class" => "SSSS","anti_dizziness" => "0","anti_dizziness_clsdfdsfdsfdsfdsfdsass" => "F","anti_critical" => "20","anti_critical_class" => "F","tenacity" => "0","tenacity_class" => "F", )); $str = json_encode($arr); echo strlen($str); //輸出1024
對redis進行10000次寫入測試
connect("127.0.0.1",6379); $redis->auth("310c8cabcdefghf2d8abcdefd44496ac80"); $start = microtime(true) ; for($i = 0; $i<10000; $i++) { $redis->set("key", $str); } echo microtime(true) - $start; //執行5次,大概平均結果為 1.7016470432281 秒
對共享內存(shm)進行10000次寫入測試
對redis進行10000次讀測試
connect("127.0.0.1",6379); $redis->auth("310c8cabcdefghf2d8abcdefd44496ac80"); $start = microtime(true) ; for($i = 0; $i<10000; $i++) { $redis->get("key"); } echo microtime(true) - $start; //執行5次,大概平均結果為 2.1236310005188 秒對共享內存(shm)進行10000次讀測試
結果清單
Redis 讀:2.1秒 寫:1.7秒
Shm 讀:0.0021秒 寫:0.0025 秒
可見,效果差別懸殊。
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/28935.html
摘要:和還有共享內存都是讀取內存的數據,為了測試一下到底效率誰更勝一籌,我在我的虛擬機下做了一次公平的測試。 redis和memcache還有共享內存都是讀取內存的數據,為了測試一下到底效率誰更勝一籌,我在我的Centos虛擬機下做了一次公平的測試。 測試參數 環境:Centos (配置忽略)、語言:PHP、WebServer:Nginx、測試次數:10000、字符類型及長度:字符串(102...
摘要:受限于的實現,程序無法使用多線程進行編程開發。比如實現一個聊天室程序,用戶在進程中處理,用戶在進程中處理,和如果在同一個,這個在多線程環境中直接用表示,和加到對應的中即可。想要解決這個問題,必須實現一個基于共享內存的數據結構。 Swoole項目從 2012 年推出到現在已經有 5 年的歷史,現在越來越多的互聯網企業使用Swoole來開發各類后臺應用。受限于 PHP 的ZendVM實現,...
閱讀 2222·2021-11-18 10:02
閱讀 3480·2021-11-15 11:36
閱讀 1116·2019-08-30 14:03
閱讀 725·2019-08-30 11:08
閱讀 2761·2019-08-29 13:20
閱讀 3287·2019-08-29 12:34
閱讀 1375·2019-08-28 18:30
閱讀 1642·2019-08-26 13:34