摘要:和還有共享內(nèi)存都是讀取內(nèi)存的數(shù)據(jù),為了測(cè)試一下到底效率誰更勝一籌,我在我的虛擬機(jī)下做了一次公平的測(cè)試。
redis和memcache還有共享內(nèi)存都是讀取內(nèi)存的數(shù)據(jù),為了測(cè)試一下到底效率誰更勝一籌,我在我的Centos虛擬機(jī)下做了一次公平的測(cè)試。
測(cè)試參數(shù)
環(huán)境:Centos (配置忽略)、語言:PHP、WebServer:Nginx、測(cè)試次數(shù):10000、字符類型及長(zhǎng)度:字符串(1024)
準(zhǔn)備測(cè)試
array ("id" => "4146","attacksdfdsfdsffffdffffdffffddd" => "5.45","atk_class" => "神圣級(jí)","wufang" => "4.9","def_class" => "超神級(jí)","cefang" => "4.9","mdf_class" => "超神級(jí)","hp" => "6.43","hp_class" => "神王級(jí)","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" => "神圣級(jí)","wufang" => "4.95","def_class" => "超神級(jí)","cefang" => "4.95","mdf_class" => "超神級(jí)","hp" => "6.43","hp_class" => "神王級(jí)","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
對(duì)redis進(jìn)行10000次寫入測(cè)試
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; //執(zhí)行5次,大概平均結(jié)果為 1.7016470432281 秒
對(duì)共享內(nèi)存(shm)進(jìn)行10000次寫入測(cè)試
對(duì)redis進(jìn)行10000次讀測(cè)試
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; //執(zhí)行5次,大概平均結(jié)果為 2.1236310005188 秒對(duì)共享內(nèi)存(shm)進(jìn)行10000次讀測(cè)試
結(jié)果清單
Redis 讀:2.1秒 寫:1.7秒
Shm 讀:0.0021秒 寫:0.0025 秒
可見,效果差別懸殊。
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/28935.html
摘要:和還有共享內(nèi)存都是讀取內(nèi)存的數(shù)據(jù),為了測(cè)試一下到底效率誰更勝一籌,我在我的虛擬機(jī)下做了一次公平的測(cè)試。 redis和memcache還有共享內(nèi)存都是讀取內(nèi)存的數(shù)據(jù),為了測(cè)試一下到底效率誰更勝一籌,我在我的Centos虛擬機(jī)下做了一次公平的測(cè)試。 測(cè)試參數(shù) 環(huán)境:Centos (配置忽略)、語言:PHP、WebServer:Nginx、測(cè)試次數(shù):10000、字符類型及長(zhǎng)度:字符串(102...
摘要:受限于的實(shí)現(xiàn),程序無法使用多線程進(jìn)行編程開發(fā)。比如實(shí)現(xiàn)一個(gè)聊天室程序,用戶在進(jìn)程中處理,用戶在進(jìn)程中處理,和如果在同一個(gè),這個(gè)在多線程環(huán)境中直接用表示,和加到對(duì)應(yīng)的中即可。想要解決這個(gè)問題,必須實(shí)現(xiàn)一個(gè)基于共享內(nèi)存的數(shù)據(jù)結(jié)構(gòu)。 Swoole項(xiàng)目從 2012 年推出到現(xiàn)在已經(jīng)有 5 年的歷史,現(xiàn)在越來越多的互聯(lián)網(wǎng)企業(yè)使用Swoole來開發(fā)各類后臺(tái)應(yīng)用。受限于 PHP 的ZendVM實(shí)現(xiàn),...
閱讀 2249·2021-11-18 10:02
閱讀 3499·2021-11-15 11:36
閱讀 1125·2019-08-30 14:03
閱讀 742·2019-08-30 11:08
閱讀 2772·2019-08-29 13:20
閱讀 3295·2019-08-29 12:34
閱讀 1382·2019-08-28 18:30
閱讀 1648·2019-08-26 13:34