Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL优于Redis_Mysql_Redis_Benchmarking - Fatal编程技术网

MySQL优于Redis

MySQL优于Redis,mysql,redis,benchmarking,Mysql,Redis,Benchmarking,我试图为mysql操作和redis操作制作一个基准脚本 以下是我尝试过的: 1./ List of comment ids with a separate hash of comment JSON Data mapped to comment id 2./ List of comments json data 3./ Sorted set of comments with ranking and json data as mapped value 出于某种原因,mysql一直在执行redi

我试图为mysql操作和redis操作制作一个基准脚本

以下是我尝试过的:

1./ List of comment ids with a separate hash of comment JSON Data mapped to comment id

2./ List of comments json data

3./ Sorted set of comments with ranking and json data as mapped value
出于某种原因,mysql一直在执行redis,我不明白为什么我正在查询100条记录。

以下是我的操作(以尝试分隔):

以下是我的基准脚本:

$client = new Predis\Client($conf);
$st=microtime(true);
// sorted set solution
$dat=$client->zrange("comments",0,100);
// list solution
//$dat=$client->lrange("comments",0,100);
$ft=microtime(true);
$overall=$ft-$st;
echo "REDIS=>".$overall."\n";

$sta=microtime(true);
$st=mysqli_query($dbh,"select SQL_NO_CACHE * from comments where status>0 order by createdate desc limit 0,100");
while($r=mysqli_fetch_assoc($st)){
  $dd=$r;
}
$fta=microtime(true);
$overall=$fta-$sta;
echo "MYSQL=>".$overall."\n";
以下是我的redis store脚本,用于排序集:

$st=mysqli_query($dbh,"select SQL_NO_CACHE * from comments where status>0 order by createdate desc LIMIT 100");
$i=1;
while($r=mysqli_fetch_assoc($st)){
  $client->zadd("comments",$i,json_encode($r));
  $i++;
}
以下是列表的我的redis商店脚本:

$st=mysqli_query($dbh,"select SQL_NO_CACHE * from comments where status>0 order by createdate desc LIMIT 100");
$i=1;
while($r=mysqli_fetch_assoc($st)){
  $key="comment:$id";
  $client->rpush("comments",$key);
  foreach($r as $k=>$v){
   $client->hset($key,$k,$v);
  }
  $i++;
}
以下是我的redis store脚本,用于无指向散列的列表:

$st=mysqli_query($dbh,"select SQL_NO_CACHE * from comments where status>0 order by createdate desc LIMIT 100");
$i=1;
while($r=mysqli_fetch_assoc($st)){
  $key="comment:$id";
  $client->rpush("comments",json_encode($r));
}
以下是DB模式:

CREATE TABLE `comments` (
  `commentid` int(11) NOT NULL AUTO_INCREMENT,
  `parentid` int(11) DEFAULT '0',
  `refno` int(11) DEFAULT '0',
  `createdate` int(11) DEFAULT '0',
  `remoteip` varchar(80) DEFAULT '',
  `fingerprint` varchar(50) DEFAULT '',
  `locid` int(11) DEFAULT '0',
  `clubid` int(11) DEFAULT '0',
  `profileid` int(11) DEFAULT '0',
  `userid` int(11) DEFAULT '0',
  `global` int(11) DEFAULT '0',
  `official` int(11) DEFAULT '0',
  `legacyuser` int(11) DEFAULT '0',
  `mediaid` int(11) DEFAULT '0',
  `status` int(11) DEFAULT '1',
  `comment` varchar(4000) DEFAULT '',
  `likes` int(11) DEFAULT '0',
  `dislikes` int(11) DEFAULT '0',
  `import` int(11) DEFAULT '0',
  `author` varchar(50) DEFAULT '',
  PRIMARY KEY (`commentid`),
  KEY `comments_locid` (`locid`),
  KEY `comments_userid` (`userid`),
  KEY `idx_legacyusers` (`legacyuser`),
  KEY `profile_index` (`profileid`),
  KEY `comments_createdate` (`createdate`),
  KEY `compound_for_comments` (`locid`,`global`,`status`),
  KEY `global` (`global`),
  KEY `status` (`status`),
  KEY `locid_status` (`locid`,`status`),
  KEY `global_status` (`global`,`status`)
) ENGINE=InnoDB
我们使用Redislabs作为我们的redis服务器。


如果我遗漏了任何问题,请让我知道。

基于以上评论,AWS中托管的远程Redis实例的网络延迟大于本地MySQL实例的延迟


当然,当你为每个Redis请求增加40-100毫秒的延迟时(取决于你的应用程序在互联网上与托管Redis的距离),它会使Redis在总请求时间上显得更慢

根据以上评论,AWS中托管的远程Redis实例的网络延迟大于本地MySQL实例的延迟


当然,当你为每个Redis请求增加40-100毫秒的延迟时(取决于你的应用程序在互联网上与托管Redis的距离),它会使Redis在总请求时间上显得更慢

如果你不提供一份报告,我们无法评估你的测试。现在@dinei怎么样?你的问题是什么?如果你说的是直接从MySQL中选择,而不是从Redis中获取。。。我并不惊讶。当存储需要反复进行的计算量更大的计算时,redis的价值就开始发挥作用。我不明白为什么我们要浪费时间将redis作为缓存后端。我的印象是,从mysql后端切换到redis内存解决方案是我们被告知要采取的方法。你说你正在使用redislabs。我猜这是一个云托管的redis实例?您是否将其与本地MySQL实例进行比较?也许是网络往返延迟使云redis看起来很慢。如果你不提供测试,我们无法评估你的测试。现在@dinei怎么样?你的问题是什么?如果你说的是直接从MySQL中选择,而不是从Redis中获取。。。我并不惊讶。当存储需要反复进行的计算量更大的计算时,redis的价值就开始发挥作用。我不明白为什么我们要浪费时间将redis作为缓存后端。我的印象是,从mysql后端切换到redis内存解决方案是我们被告知要采取的方法。你说你正在使用redislabs。我猜这是一个云托管的redis实例?您是否将其与本地MySQL实例进行比较?也许是网络往返延迟让云redis看起来很慢。正确。谢谢。正确。谢谢
CREATE TABLE `comments` (
  `commentid` int(11) NOT NULL AUTO_INCREMENT,
  `parentid` int(11) DEFAULT '0',
  `refno` int(11) DEFAULT '0',
  `createdate` int(11) DEFAULT '0',
  `remoteip` varchar(80) DEFAULT '',
  `fingerprint` varchar(50) DEFAULT '',
  `locid` int(11) DEFAULT '0',
  `clubid` int(11) DEFAULT '0',
  `profileid` int(11) DEFAULT '0',
  `userid` int(11) DEFAULT '0',
  `global` int(11) DEFAULT '0',
  `official` int(11) DEFAULT '0',
  `legacyuser` int(11) DEFAULT '0',
  `mediaid` int(11) DEFAULT '0',
  `status` int(11) DEFAULT '1',
  `comment` varchar(4000) DEFAULT '',
  `likes` int(11) DEFAULT '0',
  `dislikes` int(11) DEFAULT '0',
  `import` int(11) DEFAULT '0',
  `author` varchar(50) DEFAULT '',
  PRIMARY KEY (`commentid`),
  KEY `comments_locid` (`locid`),
  KEY `comments_userid` (`userid`),
  KEY `idx_legacyusers` (`legacyuser`),
  KEY `profile_index` (`profileid`),
  KEY `comments_createdate` (`createdate`),
  KEY `compound_for_comments` (`locid`,`global`,`status`),
  KEY `global` (`global`),
  KEY `status` (`status`),
  KEY `locid_status` (`locid`,`status`),
  KEY `global_status` (`global`,`status`)
) ENGINE=InnoDB