예제 #1
0
파일: ThreadTest.cs 프로젝트: yaobos/NCache
        /// <summary>
        /// Main test starting point. This method instantiate multiple threads and keeps track of
        /// all of them.
        /// </summary>
        public void Test()
        {
            try
            {
                Thread[] threads = new Thread[_threadCount];

                Cache cache = Factory.InitializeCache(_cacheId);
                cache.ExceptionsEnabled = true;

                string pid = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();

                for (int threadIndex = 0; threadIndex < _threadCount; threadIndex++)
                {
                    ThreadContainer tc             = new ThreadContainer(cache, _totalLoopCount, _testCaseIterations, _testCaseIterationDelay, _getsPerIteration, _updatesPerIteration, _dataSize, _expiration, _threadCount, _reportingInterval, threadIndex);
                    ThreadStart     threadDelegate = new ThreadStart(tc.DoTest);
                    threads[threadIndex]      = new Thread(threadDelegate);
                    threads[threadIndex].Name = "ThreadIndex: " + threadIndex;
                    threads[threadIndex].Start();
                }

                //--- wait on threads to complete their work before finishing
                for (int threadIndex = 0; threadIndex < threads.Length; threadIndex++)
                {
                    threads[threadIndex].Join();
                }

                cache.Dispose();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error :- " + e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
        }
예제 #2
0
        public void StartTasks()
        {
            try
            {
                Thread[]        threads    = new Thread[_threadCount];
                CacheInitParams parameters = new CacheInitParams();

                _cache = Factory.InitializeCache(_cacheId, parameters);
                _cache.ExceptionsEnabled = true;

                string pid = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();

                for (int threadIndex = 0; threadIndex < _threadCount; threadIndex++)
                {
                    StressThreadTask threadTask = new StressThreadTask(_cache, _totalLoopCount, _testCaseIterations, _testCaseIterationDelay, _getsPerIteration, _updatesPerIteration, _dataSize, _expiration, _threadCount, _reportingInterval, threadIndex, _outputProvider, _adapter);
                    _tasks.Add(threadTask);
                    threadTask.Start();
                }
                _adapter.Listen();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #3
0
 public NCache(string cacheId, string clientCacheId)
 {
     Guard.ArgumentNotNullOrEmpty(cacheId, "cacheId");
     Guard.ArgumentNotNullOrEmpty(clientCacheId, "clientCacheId");
     _cacheId       = cacheId;
     _clientCacheId = clientCacheId;
     _cache         = ANCache.InitializeCache(cacheId, clientCacheId);
 }
예제 #4
0
        internal static Alachisoft.NCache.Caching.EventId ConvertToEventID(Alachisoft.NCache.Common.Protobuf.BulkEventItemResponse eventItem, NCache.Persistence.EventType eventType)
        {
            Alachisoft.NCache.Caching.EventId eventId = eventId = new Alachisoft.NCache.Caching.EventId();

            switch (eventType)
            {
                case NCache.Persistence.EventType.ITEM_UPDATED_CALLBACK:
                    eventId.EventUniqueID = eventItem.ItemUpdatedCallback.eventId.eventUniqueId;
                    eventId.EventCounter = eventItem.ItemUpdatedCallback.eventId.eventCounter;
                    eventId.OperationCounter = eventItem.ItemUpdatedCallback.eventId.operationCounter;
                    eventId.EventType = NCache.Persistence.EventType.ITEM_UPDATED_CALLBACK;
                    break;

                case NCache.Persistence.EventType.ITEM_REMOVED_CALLBACK:
                    eventId.EventUniqueID = eventItem.itemRemoveCallback.eventId.eventUniqueId;
                    eventId.EventCounter = eventItem.itemRemoveCallback.eventId.eventCounter;
                    eventId.OperationCounter = eventItem.itemRemoveCallback.eventId.operationCounter;
                    eventId.EventType = NCache.Persistence.EventType.ITEM_REMOVED_CALLBACK;
                    break;

            }
            return eventId;
        }
예제 #5
0
            public static void Run(string[] args)
            {
                try
                {
                    object param = new DumpCacheParam();
                    CommandLineArgumentParser.CommandLineParser(ref param, args);
                    cParam = (DumpCacheParam)param;

                    if (cParam.IsUsage)
                    {
                        AssemblyUsage.PrintLogo(cParam.IsLogo);
                        AssemblyUsage.PrintUsage();
                        return;
                    }
                    if (!ValidateParameters())
                    {
                        return;
                    }

                    Cache cache = Factory.InitializeCache(cParam.CacheId);
                    cache.ExceptionsEnabled = true;

                    System.Console.WriteLine("Cache count: {0}.", cache.Count);
                    IDictionaryEnumerator keys = (IDictionaryEnumerator)cache.GetEnumerator();

                    if (keys != null)
                    {
                        long index       = 0;
                        bool checkFilter = (cParam.KeyFilter != "");
                        cParam.KeyFilter = cParam.KeyFilter.Trim();
                        while (keys.MoveNext())
                        {
                            if ((cParam.KeyCount > 0) && (index >= cParam.KeyCount))
                            {
                                break;
                            }

                            if (checkFilter == true)
                            {
                                string tmpKey = (string)keys.Key;

                                if (tmpKey.Contains(cParam.KeyFilter) == true)
                                {
                                    System.Console.WriteLine(tmpKey);
                                }
                            }
                            else
                            {
                                System.Console.WriteLine(keys.Key);
                            }
                            index++;
                        } //end while
                    }     //end if
                    cache.Dispose();
                }         //end try block
                catch (Exception e)
                {
                    Console.Error.WriteLine("Error: " + e.Message);
                    Console.Error.WriteLine();
                    Console.Error.WriteLine(e.ToString());
                }
            }