Example #1
0
        private static void TestGenericPool()
        {
            ConsoleWriter.Instance.WriteEmphasis("Generic Pool Test\n");

            IGenericObjectPool <TestPoolItem> testPool = new GenericObjectPool <TestPoolItem>(10, BalancingMethods.RoundRobin);

            List <TestPoolItem> items = new List <TestPoolItem>();

            for (var i = 0; i < 5; i++)
            {
                items.Add(testPool.AcquireItem().Result);
            }
            ConsoleWriter.Instance.WriteInformation($"Count: {testPool.Count}\tSize: {testPool.Size}");

            ConsoleWriter.Instance.WriteEmphasis("Press any key to acquire one more", true);

            var itemAdded = testPool.AcquireItem().Result;

            items.Add(itemAdded);
            ConsoleWriter.Instance.WriteInformation($"Count: {testPool.Count}\tSize: {testPool.Size}");

            ConsoleWriter.Instance.WriteEmphasis("Press any key to deactivate last added", true);
            itemAdded.Deactivate();

            ConsoleWriter.Instance.WriteInformation($"Count: {testPool.Count}\tSize: {testPool.Size}");

            ConsoleWriter.Instance.WriteEmphasis("Press any key to release all", true);

            for (var i = 0; i < items.Count; i++)
            {
                testPool.ReleaseItem(items[i]).Wait();
            }

            testPool.ContractItemPool();
            Thread.Sleep(10);

            ConsoleWriter.Instance.WriteInformation($"Count: {testPool.Count}\tSize: {testPool.Size}");

            ConsoleWriter.Instance.WriteEmphasis("Press any key to quit", true);

            testPool.Dispose();
            ConsoleWriter.Instance.Dispose();
        }
Example #2
0
        static void Main(string[] args)
        {
            var connectionString = "Data Source=DESKTOP-QMR3K93;Initial Catalog=Testing;Integrated Security=True";

            Loaders = new GenericObjectPool <DbLoader>(100, BalancingMethods.Random);

            int rowCnt = 5000;

            int loaderCnt = 0;

            DateTime start = DateTime.Now;

            for (var row = 0; row < rowCnt; row++)
            {
                List <string> columns = new List <string>();
                for (var col = 0; col < 25; col++)
                {
                    columns.Add($"somevalue{col}");
                }

                var loader = Loaders.AcquireItem(connectionString).Result;
                if (string.IsNullOrEmpty(loader.Name))
                {
                    loaderCnt++;
                    loader.Name = $"Loader {loaderCnt}";
                }
                loader.MaxCount = 500;
                loader.Activate(connectionString);

                loader.LoadIntoDatabase(columns);
            }
            var end = DateTime.Now;

            Console.WriteLine($"{Loaders.Count} loaders started in {end - start}");

            Console.WriteLine("\nPress any key to quit");
            Console.ReadKey();


            Loaders.Dispose();
        }