This repository was archived by the owner on Jul 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathProgram.cs
executable file
·51 lines (42 loc) · 1.85 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ElasticSearch.Client;
using ElasticSearch.Client.Config;
namespace BenchmarkTests
{
class Program
{
static void Main(string[] args)
{
var client = new ElasticSearchClient("10.129.8.58",9500,TransportType.Thrift);
int failure = 0;
var data = "{\"book\": \"The Hitchhiker's Guide to the Galaxy\"" +
",\"id\":"+1+
",\"chapter\": \"Chapter 11\",\"text1\": \"All the doors in this spaceship have a cheerful and sunny disposition. It is their pleasure to open for you, and their satisfaction to close again with the knowledge of a job well done.\"}";
client.Index("benchmark_test", "default", Guid.NewGuid().ToString(), data);
int count = int.Parse(args[0]);
var begin = DateTime.Now;
for (var i = 0; i < count; i++)
{
data = "{\"book\": \"The Hitchhiker's Guide to the Galaxy\"" +
",\"id\":" + i +
",\"chapter\": \"Chapter 11\",\"text1\": \"All the doors in this spaceship have a cheerful and sunny disposition. It is their pleasure to open for you, and their satisfaction to close again with the knowledge of a job well done.\"}";
client.Index("benchmark_test", "default", Guid.NewGuid().ToString(), data);
var response = client.Index("benchmark_test", "default", Guid.NewGuid().ToString(), data);
if (!response.Success)
{
failure++;
}
}
var end = DateTime.Now;
var timespan = end - begin;
var avg = timespan.TotalMilliseconds / count;
Console.WriteLine("iteration:{0},failure:{3},elapsed time:{1},avg time:{2}ms", count, timespan, avg, failure);
client.DeleteIndex("benchmark_test");
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}