本文是对Redis 单节点,针对不同的数据类型,做插入行测试. 数据总条数为:10058624

环境说明:

            Redis 未做任何优化, 单节点    (服务器上, 内存64G).

            数据量 : 10058624条  (大约一千零6万条数据,本地机器运行读取插入操作.)

            数据大小 :  1093.56MB  (1.1G)

 插入数据类型为 String 类型

Jedis插入

public void save(){
//连接本地Redis服务
Jedis jedis = new Jedis("bj-rack001-hadoop006");
InputStream fis = null;
fis = new BufferedInputStream(new FileInputStream(PATH));
//根据数据流初始化一个DBFReader实例,用来读取DBF文件信息
DBFReader reader = new DBFReader(fis); Object[] rowValues;
int index = 0; while ((rowValues = reader.nextRecord()) != null){
if (null != rowValues && rowValues.length > 0) {
index ++;
if (index %10000 == 0) {
long end = System.currentTimeMillis();
System.out.println("处理数据中 ==> 插入数据总条数 : "+index+" 总耗时 : "+ (end-start)/1000 + " s , 处理速度 : " +(index/((end-start)/1000))+" 条 / s");
}
jedis.set("index" + SEPARATOR +index, Array2String(rowValues));
}
}
jedis.close();
}

假设插入速度为 2800条/s , 那么插入10058624 条数据需要用时: 3593秒 .  (  59.88 min , 约 1小时.  )!!!!!

Pipelining插入

public void save(){
//连接本地Redis服务
Jedis jedis = new Jedis("bj-rack001-hadoop006");
Pipeline pipelined = jedis.pipelined(); InputStream fis = null;
fis = new BufferedInputStream(new FileInputStream(PATH));
//根据数据流初始化一个DBFReader实例,用来读取DBF文件信息
DBFReader reader = new DBFReader(fis); Object[] rowValues;
int index = 0; while ((rowValues = reader.nextRecord()) != null){
if (null != rowValues && rowValues.length > 0) {
index ++;
if (index %10000 == 0) {
long end = System.currentTimeMillis();
System.out.println("处理数据中 ==> 插入数据总条数 : "+index+" 总耗时 : "+ (end-start)/1000 + " s , 处理速度 : " +(index/((end-start)/1000))+" 条 / s");
}
pipelined.set("index"+ SEPARATOR +index,Array2String(rowValues));
}
}
pipelined.sync();
jedis.close();
}

处理数据完成  ==> 插入数据总条数 size : 10058624   total use : 62 s  , 处理速度: 162235 条/s

和传统方式相比,性能差将近58 倍!!!!!!!!

读取全部 String 类型数据

Jedis读取

public void save(){
//连接本地Redis服务
Jedis jedis = new Jedis("bj-rack001-hadoop006");
long start = System.currentTimeMillis(); int num = 10058624;
for (int index = 1; index < num; index++){
if (index %10000 == 0) {
long end = System.currentTimeMillis();
System.out.println("处理数据中 ==> 插入数据总条数 : "+index+" 总耗时 : "+ (end-start)/1000 + " s , 处理速度 : " +(index/((end-start)/1000))+" 条 / s");
}
String key = KEYPREFIX + SEPARATOR + index;
String value = jedis.get(key);
}
jedis.close();
}

假设插入速度为 5000条/s , 那么插入10058624 条数据需要用时: 2012 秒  .  (  33min 30 s  .  )

Pipelining读取

public void save(){
//连接本地Redis服务
Jedis jedis = new Jedis("bj-rack001-hadoop006");
Pipeline pipelined = jedis.pipelined(); long start = System.currentTimeMillis();
HashMap<String, Response<String>> intrmMap = new HashMap<String, Response<String>>(); int num = 10058624;
for (int index = 1; index < num; index++){
if (index %10000 == 0) {
long end = System.currentTimeMillis();
System.out.println("处理数据中 ==> 插入数据总条数 : "+index+" 总耗时 : "+ (end-start)/1000 + " s , 处理速度 : " +(index/((end-start)/1000))+" 条 / s");
}
String key = KEYPREFIX + SEPARATOR + index;
intrmMap.put(key, pipelined.get(key));
}
pipelined.sync();
jedis.close();
}

由于是异步操作, 所以上面的结果并不准.最终获取数据时间

batchGetUsePipeline : 处理数据完成  ==> 读取数据总条数 size : 10058623   total use : 48 s  , 处理速度: 209554 条/s 

和传统方式相比,性能差将近 41.92  倍!!!!!!!!

插入数据类型为 List 类型

Jedis插入

public void save(){
//连接本地Redis服务
Jedis jedis = new Jedis("bj-rack001-hadoop006");
InputStream fis = null;
fis = new BufferedInputStream(new FileInputStream(PATH));
//根据数据流初始化一个DBFReader实例,用来读取DBF文件信息
DBFReader reader = new DBFReader(fis); Object[] rowValues;
int index = 0; while ((rowValues = reader.nextRecord()) != null){
if (null != rowValues && rowValues.length > 0) {
index ++;
if (index %10000 == 0) {
long end = System.currentTimeMillis();
System.out.println("处理数据中 ==> 插入数据总条数 : "+index+" 总耗时 : "+ (end-start)/1000 + " s , 处理速度 : " +(index/((end-start)/1000))+" 条 / s");
}
jedis.lpush("index", JacksonUtils.toJSon(rowValues));
}
}
jedis.close();
}

假设插入速度为 2600条/s , 那么插入10058624 条数据需要用时: 3869 秒 .  (  64.5 min , 约 1小时零5分钟.  )

Pipeline 插入

public void save(){
//连接本地Redis服务
Jedis jedis = new Jedis("bj-rack001-hadoop006");
Pipeline pipelined = jedis.pipelined(); InputStream fis = null;
fis = new BufferedInputStream(new FileInputStream(PATH));
//根据数据流初始化一个DBFReader实例,用来读取DBF文件信息
DBFReader reader = new DBFReader(fis); Object[] rowValues;
int index = 0; while ((rowValues = reader.nextRecord()) != null){
if (null != rowValues && rowValues.length > 0) {
index ++;
if (index %10000 == 0) {
long end = System.currentTimeMillis();
System.out.println("处理数据中 ==> 插入数据总条数 : "+index+" 总耗时 : "+ (end-start)/1000 + " s , 处理速度 : " +(index/((end-start)/1000))+" 条 / s");
}
pipelined.lpush("index", JacksonUtils.toJSon(rowValues));
}
}
pipelined.sync();
jedis.close();
}

处理数据完成  ==> 插入数据总条数 size : 10058624   total use : 62 s  , 处理速度: 162235 条/s 

和传统方式对比  性能相差 62.5倍

读取全部 List 类型数据

Jedis读取

public void save(){
//连接本地Redis服务
Jedis jedis = new Jedis("bj-rack001-hadoop006");
long start = System.currentTimeMillis(); List<String> list = jedis.lrange("index", 0, 10058624);
jedis.close(); long end = System.currentTimeMillis();
System.out.println("处理数据中 ==> 读取数据总条数 : "+list.size()+" 耗时 : "+ start + " s , 处理速度 : " +(list.size()/((end-start)/1000))+" 条 / s");
}

读取数据总条数 size : 10058624   total use : 15 s  , 处理速度: 670574 条/s

Pipline读取

public void save(){
//连接本地Redis服务
Jedis jedis = new Jedis("bj-rack001-hadoop006");
long start = System.currentTimeMillis();
Pipeline pipelined = jedis.pipelined(); Response<List<String>> list = pipelined.lrange("index", 0, 10058624); pipelined.sync();
jedis.close(); long end = System.currentTimeMillis();
System.out.println("处理数据中 ==> 读取数据总条数 : "+list.size()+" 耗时 : "+ start + " s , 处理速度 : " +(list.size()/((end-start)/1000))+" 条 / s");
}

处理数据完成  ==> 读取数据总条数 size : 10058624   total use : 12 s  , 处理速度: 838218 条/s

pipline的数据读取方式确实会快很多, 但是内存存在消耗

文章转载至:https://blog.csdn.net/zhanglong_4444/article/details/87921162

Redis:Java链接redis单节点千万级别数据 写入,读取 性能测试的更多相关文章

  1. Redis 单节点百万级别数据 读取 性能测试.

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 这里先进行造数据,向redis中写入五百万条数据,具体方式有如下三种: 方法一:(Lua 脚本) vim ...

  2. Java链接Redis时出现 “ERR Client sent AUTH, but no password is set” 异常的原因及解决办法

    Java链接Redis时出现 "ERR Client sent AUTH, but no password is set" 异常的原因及解决办法 [错误提示] redis.clie ...

  3. Java链接Redis时出现 “ERR Client sent AUTH, but no password is set”

    Java链接Redis时出现 “ERR Client sent AUTH, but no password is set” 异常的原因及解决办法. [错误提示] redis.clients.jedis ...

  4. mysql数据库千万级别数据的查询优化和分页测试

    原文地址:原创 mysql数据库千万级别数据的查询优化和分页测试作者:于堡舰 本文为本人最近利用几个小时才分析总结出的原创文章,希望大家转载,但是要注明出处 http://blog.sina.com. ...

  5. java之5分钟插入千万条数据

    虽说不一定5分钟就插入完毕,因为取决去所插入的字段,如果字段过多会稍微慢点,但不至于太慢.10分钟内基本能看到结果. 之前我尝试用多线程来实现数据插入(百万条数据),半个多小时才二十多万条数据. 线程 ...

  6. flink04 -----1 kafkaSource 2. kafkaSource的偏移量的存储位置 3 将kafka中的数据写入redis中去 4 将kafka中的数据写入mysql中去

    1. kafkaSource 见官方文档 2. kafkaSource的偏移量的存储位置 默认存在kafka的特殊topic中,但也可以设置参数让其不存在kafka的特殊topic中   3   将k ...

  7. JAVA使用POI如何导出百万级别数据(转)

    https://blog.csdn.net/happyljw/article/details/52809244   用过POI的人都知道,在POI以前的版本中并不支持大数据量的处理,如果数据量过多还会 ...

  8. JAVA使用POI如何导出百万级别数据

    用过POI的人都知道,在POI以前的版本中并不支持大数据量的处理,如果数据量过多还会常报OOM错误,这时候调整JVM的配置参数也不是一个好对策(注:jdk在32位系统中支持的内存不能超过2个G,而在6 ...

  9. JAVA使用POI如何导出百万级别数据(转载)

    用过POI的人都知道,在POI以前的版本中并不支持大数据量的处理,如果数据量过多还会常报OOM错误,这时候调整JVM的配置参数也不是一个好对策(注:jdk在32位系统中支持的内存不能超过2个G,而在6 ...

随机推荐

  1. IDEA Git 项目实战场景

    实战场景一:上班啦,从远程仓库克隆项目到本地仓库(Clone) 打开 IDEA,在 Check out from Version Control 下拉菜单选择 Git,如下: 在弹出窗口的 URL 地 ...

  2. LT4020替代方案

    国产  替代LT4020的方案 南芯 展讯的方案 https://item.taobao.com/item.htm?spm=a230r.1.14.21.6f27bf96rrAtci&id=56 ...

  3. fdisk 磁盘分区命令

    fdisk fdisk磁盘分区命令 -v    打印 fdisk 的版本信息并退出.-l    列出指定设备的分区表信息并退出. 如果没有给出设备,那么使用那些在 /proc/partitions ( ...

  4. HUAWEI防火墙通过L2TP隧道让外出员工访问公司内网的各种资源

    组网图形 组网需求 企业网络如图所示,企业希望公司外的移动办公用户能够通过L2TP VPN隧道访问公司内网的各种资源. 操作步骤 配置LNS. 1.配置接口IP地址,并将接口加入安全区域. <L ...

  5. 树莓派 PICO基础教程(基于MicroPython)

    目录 1 树莓派 PICO 简介 1.1 简介 1.2 配置 [^2] 1.3 引脚图 1.4 尺寸 2 安装 2.1 烧录固件 2.2 安装IDE(Thonny IDE) 2.3 离线运行程序 3 ...

  6. 行者APP适配国外环境问题解决

    (本文1151字,阅读约5分钟) 玩骑行的同伴都知道,长途骑行,第一需要好的硬件,如大腿发动机.车子.装备等:二是需要好的软件,如意志.有氧能力.骑行app等. 到雅加达后,才发现在国内用了几年的黑鸟 ...

  7. curl 常用操作总结

    前言 curl 是一个强大的命令行工具,支持 HTTP, HTTPS, SCP 等多种协议,本文主要总结一下其常用的功能,方便及时查阅. curl --version curl 7.68.0 (x86 ...

  8. Mobileye独创性创新

    Mobileye独创性创新 尽管存在相似之处,但Nvidia的SFF无法与Mobileye的RSS相匹配,后者是领先的AV安全模型 迈向无人驾驶的未来,Mobileye继续以新的创新引领行业,不仅将使 ...

  9. 地理围栏API服务开发

    地理围栏API服务开发 要使用华为地理围栏服务API,需要确保设备已经下载并安装了HMS Core(APK),并将Location Kit的SDK集成到项目中. 指定应用权限 如果需要使用地理围栏服务 ...

  10. GPU上如何优化卷积

    GPU上如何优化卷积 本文将演示如何在TVM中编写高性能卷积实现.我们以平方大小的输入张量和滤波器为例,假设卷积的输入是大批量的.在本例中,使用不同的布局来存储数据,以实现更好的数据局部性.缓冲区布局 ...