bboss性能基准测试(仅供参考)

  • 批量添加2万条数据耗时1.5秒
  • 对大索引表文档统计计数耗时10毫秒
  • 获取一条json文档耗时2毫秒
  • 获取一条Object文档耗时3毫秒
  • scroll查询并处理2万条记录:0.6s
  • scrollSlice 并行查询并处理2万条记录:0.1s

测试环境

elasticsearch: 6.5.0 单机,内存配置1G

jdk 1.8

测试服务器:联想ThinkPAD S5笔记本电脑,64位 Intel i7-6700HQ 4核 16G内存,1T硬盘

性能测试代码

DocumentCRUD

  1. /**
  2. * 批量导入20002条数据
  3. */
  4. public void testBulkAddDocuments() {
  5. //创建批量创建文档的客户端对象,单实例多线程安全
  6. ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/scroll.xml");
  7. List<Demo> demos = new ArrayList<Demo>();
  8. Demo demo = null;
  9. long start = System.currentTimeMillis();
  10. for(int i = 0 ; i < 20002; i ++) {
  11. demo = new Demo();//定义第一个对象
  12. demo.setDemoId((long)i);
  13. demo.setAgentStarttime(new Date());
  14. demo.setApplicationName("blackcatdemo"+i);
  15. demo.setContentbody("this is content body"+i);
  16. if(i % 2 == 0) {
  17. demo.setName("刘德华喜欢唱歌" + i);
  18. }
  19. else{
  20. demo.setName("张学友不喜欢唱歌" + i);
  21. }
  22. demo.setOrderId("NFZF15045871807281445364228");
  23. demo.setContrastStatus(2);
  24. demos.add(demo);//添加第一个对象到list中
  25. }
  26. //批量添加或者修改2万个文档,将两个对象添加到索引表demo中,批量添加2万条记录耗时1.8s,
  27. String response = clientUtil.addDocuments("demo",//索引表
  28. "demo",//索引类型
  29. demos,"refresh=true");//为了测试效果,启用强制刷新机制,实际线上环境去掉最后一个参数"refresh=true"
  30. long end = System.currentTimeMillis();
  31. System.out.println("BulkAdd 20002 Documents elapsed:"+(end - start)+"毫秒");
  32. start = System.currentTimeMillis();
  33. //scroll查询2万条记录:0.6s,参考文档:https://my.oschina.net/bboss/blog/1942562
  34. ESDatas<Demo> datas = clientUtil.scroll("demo/_search","{\"size\":1000,\"query\": {\"match_all\": {}}}","1m",Demo.class);
  35. end = System.currentTimeMillis();
  36. System.out.println("scroll SearchAll 20002 Documents elapsed:"+(end - start)+"毫秒");
  37. int max = 6;
  38. Map params = new HashMap();
  39. params.put("sliceMax", max);//最多6个slice,不能大于share数
  40. params.put("size", 1000);//每页1000条记录
  41. datas = clientUtil.scrollSlice("demo/_search","scrollSliceQuery", params,"1m",Demo.class);
  42. //scroll上下文有效期1分钟
  43. //scrollSlice 并行查询2万条记录:0.1s,参考文档:https://my.oschina.net/bboss/blog/1942562
  44. start = System.currentTimeMillis();
  45. datas = clientUtil.scrollSliceParallel("demo/_search","scrollSliceQuery", params,"1m",Demo.class);
  46. end = System.currentTimeMillis();
  47. System.out.println("scrollSlice SearchAll 20002 Documents elapsed:"+(end - start)+"毫秒");
  48. if(datas != null){
  49. System.out.println("scrollSlice SearchAll datas.getTotalSize():"+datas.getTotalSize());
  50. if(datas.getDatas() != null)
  51. System.out.println("scrollSlice SearchAll datas.getDatas().size():"+datas.getDatas().size());
  52. }
  53. long count = clientUtil.countAll("demo");
  54. System.out.println("addDocuments-------------------------" +count);
  55. //System.out.println(response);
  56. //获取第一个文档
  57. response = clientUtil.getDocument("demo",//索引表
  58. "demo",//索引类型
  59. "2");//w
  60. // System.out.println("getDocument-------------------------");
  61. // System.out.println(response);
  62. //获取第二个文档
  63. demo = clientUtil.getDocument("demo",//索引表
  64. "demo",//索引类型
  65. "3",//文档id
  66. Demo.class);
  67. }