11using System ;
2+ using System . Collections . Generic ;
23using System . Diagnostics ;
34using System . Linq ;
45using Nest ;
@@ -7,96 +8,52 @@ namespace Profiling.Indexing
78{
89 class Program
910 {
10- const string INDEX_PREFIX = "proto-load-test-" ;
11- const int HTTP_PORT = 9200 ;
12- const int THRIFT_PORT = 9500 ;
13-
14- // Total number of messages to send to elasticsearch
15- const int NUM_MESSAGES = 250000 ;
16-
17- // Number of messages to buffer before sending via bulk API
18- const int BUFFER_SIZE = 1000 ;
11+ static IEnumerable < Tester > Testers ( )
12+ {
13+ yield return new HttpTester ( ) ;
14+ yield return new HttpClientTester ( ) ;
15+ yield return new ThriftTester ( ) ;
16+ }
1917
2018 static void Main ( string [ ] args )
2119 {
20+ var warmup = new HttpTester ( ) . RunTests ( 10 ) ;
2221
23- var process = Process . GetCurrentProcess ( ) ;
24- var baseThreadCount = process . Threads . Count ;
25- var baseMemorySize = process . VirtualMemorySize64 ;
26- var host = "localhost" ;
27- if ( Process . GetProcessesByName ( "fiddler" ) . Any ( ) )
28- host = "ipv4.fiddler" ;
29- var client = new ElasticClient ( new ConnectionSettings ( new Uri ( "http://" + host + ":9200" ) , "nest-default-index" ) ) ;
30- //warmer
31- RunTest < HttpTester > ( HTTP_PORT , 10 ) ;
32-
33- client . Refresh ( ) ;
34-
35- Console . WriteLine ( "Warmed up caches press any key to index {0} messages" , NUM_MESSAGES ) ;
22+ Console . WriteLine ( "Warmed up caches to start testing, press any key to start tests" ) ;
3623 Console . ReadLine ( ) ;
24+
3725 ConsoleKeyInfo key ;
3826 do
3927 {
40- key = RunIndex ( baseThreadCount , baseMemorySize ) ;
28+ var results = Testers ( ) . Select ( t => t . RunTests ( ) ) . ToList ( ) ;
29+ Console . WriteLine ( ) ;
30+ foreach ( var r in results )
31+ PrintRunResults ( r ) ;
32+
33+ Console . WriteLine ( "\n Press r to index again or any other key to delete indices created by this tool.\n " ) ;
34+ key = Console . ReadKey ( ) ;
4135 } while ( key . KeyChar == 'r' ) ;
4236
43- RunIndex ( baseThreadCount , baseMemorySize ) ;
44-
45- client . DeleteIndex ( d => d . Index ( INDEX_PREFIX + "*" ) ) ;
46-
37+ var client = new ElasticClient ( ) ;
38+ client . DeleteIndex ( d => d . Index ( Tester . INDEX_PREFIX + "*" ) ) ;
4739 }
4840
49- private static ConsoleKeyInfo RunIndex ( int baseThreadCount , long baseMemorySize )
41+ private static void PrintRunResults ( RunResults runResult )
5042 {
51- var process = Process . GetCurrentProcess ( ) ;
52- double httpRate = RunTest < HttpTester > ( HTTP_PORT ) ;
53- var threadCountHttp = process . Threads . Count ;
54- var memorySizeHttp = process . VirtualMemorySize64 ;
55-
56- Console . WriteLine ( ) ;
57- Console . WriteLine ( "HTTP (IndexManyAsync): {0:0,0}/s\r (Before:After) {1}:{2} Threads {3}:{4} Virtual memory"
58- , httpRate , baseThreadCount , threadCountHttp , baseMemorySize , memorySizeHttp ) ;
59-
60- Console . WriteLine ( "Press r to index again or any other key to delete indices created by this tool." ) ;
61- return Console . ReadKey ( ) ;
62- }
63-
64- private static double RunTest < T > ( int port , int ? messages = null ) where T : ITester
65- {
66- string type = typeof ( T ) . Name . ToLowerInvariant ( ) ;
67- Console . WriteLine ( "Starting {0} test" , type ) ;
68-
69- // Recreate index up-front, so this process doesn't interfere with perf figures
70- Stopwatch sw = new Stopwatch ( ) ;
71- sw . Start ( ) ;
72-
73- var tester = Activator . CreateInstance < T > ( ) ;
74-
75- tester . Run ( INDEX_PREFIX + type + "-" + Guid . NewGuid ( ) . ToString ( ) , port , messages ?? NUM_MESSAGES , BUFFER_SIZE ) ;
76-
77- sw . Stop ( ) ;
78- double rate = NUM_MESSAGES / ( ( double ) sw . ElapsedMilliseconds / 1000 ) ;
79-
80- Console . WriteLine ( "{0} index test completed in {1}ms ({2:0,0}/s)" , type , sw . ElapsedMilliseconds , rate ) ;
81-
82- //var numberOfSearches = 10000;
83-
84- //sw.Restart();
85- //tester.SearchUsingSingleClient(INDEX_PREFIX + type, port, numberOfSearches);
86- //double singleClientSearchRate = numberOfSearches / ((double)sw.ElapsedMilliseconds / 1000);
87- //Console.WriteLine("{0} search single client test completed in {1}ms ({2:0,0}/s)", type, sw.ElapsedMilliseconds, singleClientSearchRate);
88-
89- //sw.Restart();
90- //tester.SearchUsingMultipleClients(INDEX_PREFIX + type, port, numberOfSearches);
91- //double multiClientSearchRate = numberOfSearches / ((double)sw.ElapsedMilliseconds / 1000);
92- //Console.WriteLine("{0} search multi client test completed in {1}ms ({2:0,0}/s)", type, sw.ElapsedMilliseconds, multiClientSearchRate);
93-
94- //// Close the index so we don't interfere with the next test
95- //CloseIndex(type);
96-
97- return rate ;
43+ Console . WriteLine ( "---{0}\t ---------------" , runResult . TesterName ) ;
44+ Console . WriteLine ( " {0:0,0} msg/s {1} ms {2} docs" ,
45+ runResult . RatePerSecond ,
46+ runResult . ElapsedMillisecond ,
47+ runResult . IndexedDocuments
48+ ) ;
49+ var maxEsTime = runResult . EsTimings . Max ( ) ;
50+ var meanEsTime = runResult . EsTimings . GetMedian ( ) ;
51+ Console . WriteLine ( " max es-time:{0} mean es-time:{1}" , maxEsTime , meanEsTime ) ;
52+ Console . WriteLine ( " memory before:{0} thread count before:{1}" ,
53+ runResult . Before . MemorySize , runResult . Before . ThreadCount ) ;
54+ Console . WriteLine ( " memory after:{0} thread count after:{1}" ,
55+ runResult . After . MemorySize , runResult . After . ThreadCount ) ;
9856 }
9957
100-
10158 }
10259}
0 commit comments