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. fasttext学习笔记

    When to use FastText? The main principle behind fastText is that the morphological structure of a wo ...

  2. 【LeetCode每天一题】3Sum Closest(最接近的三数和)

    Given an array nums of n integers and an integer target, find three integers in nums such that the s ...

  3. node使用 log4js

    log4js //配置日志的输出级别,共ALL<TRACE<DEBUG<INFO<WARN<ERROR<FATAL<MARK<OFF八个级别,defau ...

  4. github pages搭建网站(三)

    一.个人站点 访问 https://用户名.github.io 搭建步骤 (1)创建个人站点 ->新建仓库(注:仓库名必须是[用户名.github.io]) (2)在仓库下新建index.htm ...

  5. python开源数据库gadfly安装排除错误

    从sourceforge.net上下载的,结果需要仔细看网页才能找到下载地址.下载zip包,它没有把下载地址放在显眼的地方. 安照提示,python setup.py结果提示出错.看帮助文件,需要运行 ...

  6. Mybatis select、insert、update、delete 增删改查操作

    MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架. MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设置以及对结果集的检索.MyBatis 可以使用简单的XML ...

  7. 在屏幕拖拽3D物体移动

    3D物体的拖拽不同于2D的.因为3D物体有x,y,z当然.实际拖拽还是在XZ平面.只是多了几个转换 using UnityEngine; using System.Collections; publi ...

  8. node.js初识06

    node中的fs文件系统 var http = require("http"); var fs = require("fs"); var server = ht ...

  9. jQuery-动画点击淡化消失

    <!DOCTYPE html> <html> <head> <title> new document </title> <meta c ...

  10. Unity shader学习之逐像素漫反射光照模型

    shader如下: Shader "Custom/Diffuse Fragment-Level" { Properties { _Diffuse (,,,) } SubShader ...