Esempio n. 1
0
        private static void PrintStats()
        {
            string str = string.Join(",", IgniteFactory.GetIgnite().GetCacheNames()
                                     .Select(c => IgniteFactory.GetIgnite().GetCache <object, object>(c))
                                     .Select(c => $"{c.Name}: {c.GetLocalSize()}/{c.GetSize()}"));

            Console.WriteLine(str);
        }
Esempio n. 2
0
        public static async void LoadCachesDistributed()
        {
            var funcs = ReflectionHelper.GetTimTypes().Select(t => new LoadCacheAction {
                Type = t
            });
            var sw = Stopwatch.StartNew();
            await IgniteFactory.GetIgnite().GetCompute().RunAsync(funcs);

            Console.WriteLine($"LoadCachesDistributed took {sw.Elapsed}");
            await IgniteFactory.GetIgnite().GetCompute().BroadcastAsync(new PrintMessageAction {
                Message = $"LoadCachesDistributed took {sw.Elapsed}"
            });
        }
Esempio n. 3
0
        private static void RunDbStressTest()
        {
            Console.WriteLine($"Starting DB stress test");
            var sw      = Stopwatch.StartNew();
            int counter = 0;

            Parallel.ForEach(ReflectionHelper.GetTimTypes(), t =>
            {
                var ctx = new TimDbContext();

                var rnd        = new Random();
                var repository = ctx.GetType().GetProperties().FirstOrDefault(p => p.Name == t.Name).GetValue(ctx);
                var cache      = IgniteFactory.GetIgnite().GetCache <int, object>(t.Name);; //GetOrCreateCache(t);
                var size       = ReflectionHelper.GetCacheSize(cache);
                if (size < 2)
                {
                    return;
                }
                if (t.GetProperty("ID") == null)
                {
                    return;
                }

                if (t.Assembly.GetType($"{t.Name}ComplexPK") != null)
                {
                    return;
                }

                for (int i = 0; i < 1000; i++)
                {
                    var key = rnd.Next(1, size - 1);
                    try
                    {
                        var item = repository.GetType().GetMethod("Find").Invoke(repository, new object[] { new object[] { key } });
                        if (item != null)
                        {
                            counter++;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Exception in {t.Name}");
                        return;
                    }
                }
            });
            Console.WriteLine($"DB stress test for {counter} items finished in {sw.Elapsed}");
        }
Esempio n. 4
0
        private static void RunIgniteStressTest()
        {
            Console.WriteLine($"Starting Ignite stress test");
            var sw      = Stopwatch.StartNew();
            int counter = 0;

            //foreach (var t in GetTimTypes())
            Parallel.ForEach(ReflectionHelper.GetTimTypes(), t =>
            {
                var cache = IgniteFactory.GetIgnite().GetCache <int, object>(t.Name);; //GetOrCreateCache(t);
                var rnd   = new Random();
                var size  = ReflectionHelper.GetCacheSize(cache);
                if (size < 2)
                {
                    return;
                }
                if (t.GetProperty("ID") == null)
                {
                    return;
                }
                if (t.Assembly.GetType($"{t.Name}ComplexPK") != null)
                {
                    return;
                }
                for (int i = 0; i < 1000; i++)
                {
                    var key = rnd.Next(1, size - 1);
                    if (cache.ContainsKey(key))
                    {
                        var item = cache[key];
                        counter++;
                    }
                }
            });
            Console.WriteLine($"Ignite stress test for {counter} items finished in {sw.Elapsed}");
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            Ignition.ClientMode = args.Any(s => s.Contains("client"));

            if (!Ignition.ClientMode)
            {
                Environment.SetEnvironmentVariable("IGNITE_H2_DEBUG_CONSOLE", "true");
            }

            IgniteFactory.GetIgnite();

            if (Ignition.ClientMode)
            {
                IgniteFactory.CreateLocalCaches();
            }

            Console.WriteLine("\n>>> Example started\n\n");
            Console.WriteLine("Press Q to quit, L to reload caches, R to run query, D for DB stress test, S for Ignite stress test, any key to display local stats");

            while (true)
            {
                switch (Console.Read())
                {
                case 'q':
                    return;

                case 'l':
                    IgniteFactory.LoadCaches();
                    break;

                case 'r':
                    RunQueryGetBudgetDataSections();
                    break;

                case 'p':
                    var actions = new List <Action>();
                    for (int i = 0; i < 10; i++)
                    {
                        actions.Add(RunQueryPPRV);
                    }
                    Parallel.Invoke(actions.ToArray());
                    break;

                case 's':
                    RunIgniteStressTest();
                    break;

                case 'd':
                    RunDbStressTest();
                    break;

                case '\r':
                case '\n':
                    break;

                default:
                    PrintStats();
                    break;
                }
            }
        }