针对httptest4net构建elasticsearch集群压力测试用例

httptest4net是可以自定义HTTP压力测试的工具,用户可以根据自己的情况编写测试用例加载到httptest4net中并运行测试。由于最近需要对elasticsearch搜索集群进行一个不同情况的测试,所以针对这个测试写了个简单的测试用例。

代码

  1  [Test("ES base")]
  2     public class ES_SearchUrlTester : IUrlTester
  3     {
  4
  5         public ES_SearchUrlTester()
  6         {
  7
  8
  9         }
 10         public string Url
 11         {
 12             get;
 13             set;
 14         }
 15
 16
 17         static string[] urls = new string[] {
 18             "http://192.168.20.156:9200/gindex/gindex/_search",
 19             "http://192.168.20.158:9200/gindex/gindex/_search",
 20             "http://192.168.20.160:9200/gindex/gindex/_search" };
 21
 22         private static long mIndex = 0;
 23
 24         private static List<string> mWords;
 25
 26         protected static IList<string> Words()
 27         {
 28
 29             if (mWords == null)
 30             {
 31                 lock (typeof(ES_SearchUrlTester))
 32                 {
 33                     if (mWords == null)
 34                     {
 35                         mWords = new List<string>();
 36                         using (System.IO.StreamReader reader = new StreamReader(@"D:\main.dic"))
 37                         {
 38                             string line;
 39
 40                             while ((line = reader.ReadLine()) != null)
 41                             {
 42                                 mWords.Add(line);
 43                             }
 44                         }
 45                     }
 46                 }
 47             }
 48             return mWords;
 49         }
 50         /*
 51           {"query" :
 52     {
 53   "bool" : {
 54     "should" : [ {
 55       "field" : {
 56         "title" : "#key"
 57       }
 58     }, {
 59       "field" : {
 60         "kw" : "#key"
 61       }
 62     } ]
 63   }
 64     },
 65 from:0,
 66 size:10
 67 }
 68          */
 69         private static string GetSearchUrlWord()
 70         {
 71             IList<string> words= Words();
 72             System.Threading.Interlocked.Increment(ref mIndex);
 73             return Resource1.QueryString.Replace("#key", words[(int)(mIndex % words.Count)]);
 74         }
 75
 76         public System.Net.HttpWebRequest CreateRequest()
 77         {
 78             var httpWebRequest = (HttpWebRequest)WebRequest.Create(urls[mIndex%urls.Length]);
 79             httpWebRequest.ContentType = "application/json";
 80             httpWebRequest.KeepAlive = false;
 81             httpWebRequest.Method = "POST";
 82             string json = GetSearchUrlWord();
 83             using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
 84             {
 85
 86                 streamWriter.Write(json);
 87                 streamWriter.Flush();
 88             }
 89             return httpWebRequest;
 90
 91         }
 92
 93         public TestType Type
 94         {
 95             get
 96             {
 97                 return TestType.POST;
 98             }
 99         }
100     }

用例很简单根据节点和关键字构建不同请求的URL和JSON数据包即可完成。把上面代码编译在DLL后放到httptest4net的运行目录下即可以加载这用例并进行测试。

测试情况

下载httptest4net

时间: 2024-08-28 15:23:26

针对httptest4net构建elasticsearch集群压力测试用例的相关文章

针对httptest4net构建elasticsearch集群压力测用例

httptest4net是可以自定义HTTP压力测试的工具,用户可以根据自己的情况编写测试用例加载到httptest4net中并运行测试.由于最近需要对elasticsearch搜索集群进行一个不同情况的测试,所以针对这个测试写了个简单的测试用例. 代码 [Test("ES base")] public class ES_SearchUrlTester : IUrlTester { public ES_SearchUrlTester() { } public string Url {

2.使用Helm构建ElasticSearch集群

作者 微信:tangy8080 电子邮箱:[email protected] 更新时间:2019-05-24 16:08:53 星期五 欢迎您订阅和分享我的订阅号,订阅号内会不定期分享一些我自己学习过程中的编写的文章 如您在阅读过程中发现文章错误,可添加我的微信 tangy8080 进行反馈.感谢您的支持. 文章主题 利用Helm在k8s集群上搭建一个ElasticSearch集群 前置条件 有一个k8s集群 搭建好了NFS服务器 已经安装好了Helm 正文 安装nfs-client-provi

手把手教你搭建一个 Elasticsearch 集群

为何要搭建 Elasticsearch 集群 凡事都要讲究个为什么.在搭建集群之前,我们首先先问一句,为什么我们需要搭建集群?它有什么优势呢? 高可用性 Elasticsearch 作为一个搜索引擎,我们对它的基本要求就是存储海量数据并且可以在非常短的时间内查询到我们想要的信息.所以第一步我们需要保证的就是 Elasticsearch 的高可用性,什么是高可用性呢?它通常是指,通过设计减少系统不能提供服务的时间.假设系统一直能够提供服务,我们说系统的可用性是 100%.如果系统在某个时刻宕掉了,

ElasticSearch实战系列一: ElasticSearch集群+Kinaba安装教程

前言 本文主要介绍的是ElasticSearch集群和kinaba的安装教程. ElasticSearch介绍 ElasticSearch是一个基于Lucene的搜索服务器,其实就是对Lucene进行封装,提供了 REST API 的操作接口. ElasticSearch作为一个高度可拓展的开源全文搜索和分析引擎,可用于快速地对大数据进行存储,搜索和分析. ElasticSearch主要特点:分布式.高可用.异步写入.多API.面向文档 . ElasticSearch核心概念:近实时,集群,节点

搭建一个Elasticsearch集群

一.为何要搭建 Elasticsearch 集群 凡事都要讲究个为什么.在搭建集群之前,我们首先先问一句,为什么我们需要搭建集群?它有什么优势呢? (1)高可用性 Elasticsearch 作为一个搜索引擎,我们对它的基本要求就是存储海量数据并且可以在非常短的时间内查询到我们想要的信息.所以第一步我们需要保证的就是 Elasticsearch 的高可用性,什么是高可用性呢?它通常是指,通过设计减少系统不能提供服务的时间.假设系统一直能够提供服务,我们说系统的可用性是 100%.如果系统在某个时

Elasticsearch集群知识笔记

Elasticsearch集群知识笔记 Elasticsearch内部提供了一个rest接口用于查看集群内部的健康状况: curl -XGET http://localhost:9200/_cluster/health response结果: { "cluster_name": "format-es", "status": "green", ... } 这里的status有3种状态,分别是green(所有主分片和复制分片都可用

Linux下构建MySQL集群

构建MySQL集群 一.目标 1.安装MySQL-Cluster相关软件包. 2.依次配置管理/数据/SQL节点. 3.启动并测试MySQL-Cluster集群架构. 二.方案 使用6台RHEL 6.5虚拟机,如图所示.其中sql1和sql2作为SQL节点,ndb1和ndb2作为数据节点,mgmsvr作为管理节点,这5个节点构成MySQL Cluster体系:而另一台虚拟机192.168.4.1作为测试客户机. 构成MySQL集群体系的5个节点应安装Cluster版的MySQL相关软件包:测试用

elasticsearch集群介绍及优化【转】

elasticsearch用于构建高可用和可扩展的系统.扩展的方式可以是购买更好的服务器(纵向扩展)或者购买更多的服务器(横向扩展),Elasticsearch能从更强大的硬件中获得更好的性能,但是纵向扩展也有一定的局限性.真正的扩展应该是横向的,它通过增加节点来传播负载和增加可靠性.对于大多数数据库而言,横向扩展意味着你的程序将做非常大的改动来利用这些新添加的设备.对比来说,Elasticsearch天生是分布式的:它知道如何管理节点来提供高扩展和高可用.这意味着你的程序不需要关心这些.对于大

ELK+Filebeat+Nginx集中式日志解决方案(二)——添加ElasticSearch集群

一.使用说明: Elasticsearch插件:  Elasticsearch常用的几个插件为: # head # 地址  https://github.com/mobz/elasticsearch-head mobz/elasticsearch-head # kopf # 地址  https://github.com/lmenezes/elasticsearch-kopf lmenezes/elasticsearch-kopf # bigdesk # 地址 https://github.com