redis和memcache还有共享内存都是读取内存的数据,为了测试一下到底效率谁更胜一筹,我在我的Centos虚拟机下做了一次公平的测试。

测试参数

环境:Centos (配置忽略)、语言:PHP、WebServer:Nginx、测试次数:10000、字符类型及长度:字符串(1024)

准备测试

测试数据

<?php
//测试数据
$arr = array( =>
array ('id' => '','attacksdfdsfdsddddddddddd' => '5.45','atk_class' => '神圣级','wufang' => '4.9','def_class' => '超神级','cefang' => '4.9','mdf_class' => '超神级','hp' => '6.43','hp_class' => '神王级','dodge' => '','dodge_class' => 'SSSS','crit' => '','crit_class' => 'SSS','penetrate' => '','penetrate_class' => 'SSSS','mingzhong' => '','hit_class' => 'SSSS','anti_dizziness' => '','anti_dizzinesssdfdsfdsfdsfdsfds_class' => 'F','anti_critical' => '','anti_critical_class' => 'F','tenacity' => '','tenacity_class' => 'F',
),
=>
array ('id' => '414ddffff7','attack' => '5.45','atk_class' => '神圣级','wufang' => '4.95','def_class' => '超神级','cefang' => '4.95','mdf_class' => '超神级','hp' => '6.43','hp_class' => '神王级','dodge' => '','dodge_class' => 'SSSS','crit' => '','crit_class' => 'SSS','penetrate' => '','penetrate_class' => 'SSSS','mingzhong' => '','hit_class' => 'SSSS','anti_dizziness' => '','anti_dizziness_clsdfdsfdsfdsfdsfdsass' => 'F','anti_critical' => '','anti_critical_class' => 'F','tenacity' => '','tenacity_class' => 'F',
)); $str = json_encode($arr);
echo strlen($str); //输出1024

对redis进行10000次写入测试

<?php
$redis = new Redis();
$redis->connect('127.0.0.1',);
$redis->auth('310c8cabcdefghf2d8abcdefd44496ac80');
$start = microtime(true) ; for($i = ; $i<; $i++) {
$redis->set('key', $str);
}
echo microtime(true) - $start; //执行5次,大概平均结果为 1.7016470432281 秒

对共享内存(shm)进行10000次写入测试

<?php
$key = 0x4337b123;
$size = ;
$shmid = @shmop_open($key, 'c', , $size);
$start = microtime(true);
for($i = ; $i<; $i++) {
shmop_write($shmid, $str, );
}
@shmop_close($shmid);
echo microtime(true) - $start; //执行5次,大概平均结果为 0.0025370121002197 秒

对redis进行10000次读测试

<?php
$redis = new Redis();
$redis->connect('127.0.0.1',);
$redis->auth('310c8cabcdefghf2d8abcdefd44496ac80');
$start = microtime(true) ; for($i = ; $i<; $i++) {
$redis->get('key');
}
echo microtime(true) - $start; //执行5次,大概平均结果为 2.1236310005188 秒

对共享内存(shm)进行10000次读测试

<?php
$key = 0x4337b123;
$size = ;
$shmid = @shmop_open($key, 'c', , $size);
$start = microtime(true);
for($i = ; $i<; $i++) {
shmop_read($shmid, ,);
}
@shmop_close($shmid);
echo microtime(true) - $start; //执行5次,大概平均结果为 0.0021078586578369 秒

结果清单

Redis     读:2.1秒             写:1.7秒

Shm       读:0.0021秒      写:0.0025 秒

可见,效果差别悬殊。

Centos下10000次循环测试php对Redis和共享内存(shm)读写效率的更多相关文章

  1. Centos下安装Lamp和vsftpd、redis

    yum安装httpd和php.mysql服务 yum search httpd //搜索httpd开头的软件包 yum install httpd.x86_64 //找到apache 对应的软件包名 ...

  2. 设置Redis最大占用内存

    https://blog.csdn.net/happyrabbit456/article/details/54945667 Redis需要设置最大占用内存吗?如果Redis内存使用超出了设置的最大值会 ...

  3. linux下共享内存mmap和DMA(直接访问内存)的使用 【转】

    转自:http://blog.chinaunix.net/uid-7374279-id-4413316.html 介绍Linux内存管理和内存映射的奥秘.同时讲述设备驱动程序是如何使用“直接内存访问” ...

  4. Linux下多任务间通信和同步-mmap共享内存

    Linux下多任务间通信和同步-mmap共享内存 嵌入式开发交流群280352802,欢迎加入! 1.简介 共享内存可以说是最有用的进程间通信方式.两个不用的进程共享内存的意思是:同一块物理内存被映射 ...

  5. Linux下进程间通信方式——共享内存

    1.什么是共享内存? 共享内存就是允许两个或多个进程共享一定的存储区.就如同 malloc() 函数向不同进程返回了指向同一个物理内存区域的指针.当一个进程改变了这块地址中的内容的时候,其它进程都会察 ...

  6. CentOS下Redis服务器安装配置

    说明: 操作系统:CentOS 1.安装编译工具 yum install wget  make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-de ...

  7. CentOS下redis集群安装

    环境: 一台CentOS虚拟机上部署六个节点,创建3个master,3个slave节点 1.下载并解压 cd /root wget http://download.redis.io/releases/ ...

  8. CentOS 下 redis 安装与配置

    CentOS 下 redis 安装与配置   1.到官网上找到合适版本下载解压安装 [root@java src]# wget -c http://redis.googlecode.com/files ...

  9. Redis 对比 Memcached 并在 CentOS 下进行安装配置

    了解一下 Redis Redis 是一个开源.支持网络.基于内存.键值对的 Key-Value 数据库,使用 ANSI C 编写,并提供多种语言的 API ,它几乎没有上手难度,只需要几分钟我们就能完 ...

随机推荐

  1. OAuth2.0标准类库汇总

    转载官网: https://oauth.net/code/ https://www.w3cschool.cn/oauth2/5ghz1jab.html 服务端类库 .NET .NET DotNetOp ...

  2. python windows 安装gensim

    安装gensim要确定numpy和scipy安装 再安装gensim

  3. PHP语句函数

    运算符 +.-.*./.++.--.+=.-=.% 字符串拼接用.      js里面用+拼接 逻辑运算符 and &&  .  or ||   . ! 错误运算符 @(可以抑制错误) ...

  4. Lua之math

    Lua之math函数: 转载请注明出处:http://www.cnblogs.com/jietian331/p/8032555.html abs 取绝对值 math.abs(-15) 15 acos ...

  5. linux命令目录

    一.文件和目录.(文件目录的增删改查) ls pwd cd mkdir touch rmdir ln dd rm cp mv nl cat tac more less head tail stat # ...

  6. QT5 QT4--LNK2019 无法解析的外部符号

    新创建的工程 #include <QtWidgets/QApplication> #include <QtWidgets/QWidget> #include <QtWid ...

  7. 读取文件任意位置的内容——RandomAccessFile

    http://www.cnblogs.com/Sunw/p/3801145.html http://www.cnblogs.com/dukc/p/4776868.html http://www.cnb ...

  8. 排序(Sort)-----选择排序

       声明:文中动画转载自https://blog.csdn.net/qq_34374664/article/details/79545940    1.选择排序简介 选择排序(Select Sort ...

  9. 开源IOT平台

    用于IoT应用程序开发的10大开源软件: 1. DeviceHive DeviceHive基于AllJoyn的Data Art设备,同时也是AllSeen的联盟成员.这一款免费开源机器和机器通信(M2 ...

  10. 关于在搜索栏的一些小bug

    问题:我们在使用input标签和button按钮写搜索框的时候,书写在两行的时候会有缝隙,其次,input标签如果用大的div括起来,里面依然会显示边框. 解决方法:1.关于input标签,我们将属性 ...