Exemplo n.º 1
0
        public static void Run(string[] args)
        {
            Environment.SetEnvironmentVariable("hazelcast.logging.level", "info");
            Environment.SetEnvironmentVariable("hazelcast.logging.type", "console");

            var config = new Configuration {
                ClusterName = "dev"
            };

            config.ConfigureNetwork(networkConfig =>
            {
                networkConfig.SmartRouting = false;
                networkConfig.Addresses.Add("127.0.0.1:5701");
            });

            var client = HazelcastClient.NewHazelcastClient(config);
            var map    = client.GetMap <int, string>("test");
            var map2   = client.GetMap <int, string>("test3");

            map.Clear();
            map2.Clear();

            long totalDuration = 0;
            int  count         = 100;

            for (int i = 0; i < count; i++)
            {
                TransactionOptions options = new TransactionOptions()
                                             .SetTransactionType(TransactionOptions.TransactionType.TwoPhase);
                ITransactionContext context = client.NewTransactionContext(options);

                var watch = System.Diagnostics.Stopwatch.StartNew();

                context.BeginTransaction();
                var tmap  = context.GetMap <int, string>("test");
                var tmap2 = context.GetMap <int, string>("test2");

                tmap.Set(i, "value");
                tmap2.Set(i, "value");
                context.CommitTransaction();

                watch.Stop();
                totalDuration += watch.ElapsedMilliseconds;
            }
            Console.WriteLine((double)totalDuration / count);
        }