public Stats GetAndReset() { long putsNow = Interlocked.Exchange(ref puts, 0); long getsNow = Interlocked.Exchange(ref gets, 0); long removesNow = Interlocked.Exchange(ref removes, 0); long exceptionsNow = Interlocked.Exchange(ref exceptions, 0); var newOne = new Stats(); Interlocked.Exchange(ref newOne.puts, putsNow); Interlocked.Exchange(ref newOne.gets, getsNow); Interlocked.Exchange(ref newOne.removes, removesNow); Interlocked.Exchange(ref newOne.exceptions, exceptionsNow); return newOne; }
static void Main(string[] args) { Environment.SetEnvironmentVariable("hazelcast.logging.type", "console"); Environment.SetEnvironmentVariable("hazelcast.client.request.timeout", "250000"); var clientConfig = new ClientConfig(); clientConfig.GetNetworkConfig().AddAddress("192.168.2.50:5701"); clientConfig.GetNetworkConfig().SetConnectionAttemptLimit(1000); hazelcast = HazelcastClient.NewHazelcastClient(clientConfig); Console.WriteLine("Client Ready to go"); stats = new Stats(); //Thread.Sleep(100000); if (args != null && args.Length > 0) { foreach (string _arg in args) { string arg = _arg.Trim(); //if (arg.startsWith("t")) { // THREAD_COUNT = Integer.parseInt(arg.substring(1)); //} else if (arg.startsWith("c")) { // ENTRY_COUNT = Integer.parseInt(arg.substring(1)); //} else if (arg.startsWith("v")) { // VALUE_SIZE = Integer.parseInt(arg.substring(1)); //} else if (arg.startsWith("g")) { // GET_PERCENTAGE = Integer.parseInt(arg.substring(1)); //} else if (arg.startsWith("p")) { // PUT_PERCENTAGE = Integer.parseInt(arg.substring(1)); //} } } else { Console.WriteLine("Help: sh test.sh t200 v130 p10 g85 "); Console.WriteLine(" // means 200 threads, value-size 130 bytes, 10% put, 85% get"); Console.WriteLine(""); } Console.WriteLine("Starting Test with "); Console.WriteLine(" Thread Count: " + THREAD_COUNT); Console.WriteLine(" Entry Count: " + ENTRY_COUNT); Console.WriteLine(" Value Size: " + VALUE_SIZE); Console.WriteLine(" Get Percentage: " + GET_PERCENTAGE); Console.WriteLine(" Put Percentage: " + PUT_PERCENTAGE); Console.WriteLine(" Remove Percentage: " + (100 - (PUT_PERCENTAGE + GET_PERCENTAGE))); var tasks = new List<Task>(); for (int i = 0; i < THREAD_COUNT; i++) { var t = new Task(()=> HzTask(hazelcast),TaskCreationOptions.LongRunning); tasks.Add(t); t.Start(); } var tm = new Thread(StatDisplayTask); tm.Start(); Task.WaitAll(tasks.ToArray()); tm.Abort(); Console.WriteLine("--THE END--"); //Task.Factory.StartNew(StatDisplayTask); //startNew.Wait(); //StatDisplayTask(); //Task.Factory.Scheduler.MaximumConcurrencyLevel = THREAD_COUNT; Console.ReadKey(); }