Example #1
0
        /// <summary>
        /// Start
        /// </summary>
        /// <param name="setting"></param>
        /// <param name="serializer"></param>
        public static void Start(CacheSetting setting, ICacheSerializer serializer)
        {
            _serializer        = serializer;
            _entityQueueTimer  = new Timer(OnEntitySyncQueue, null, 60, 500);
            _entityQueueWacher = new Timer(CheckEntityQueue, null, 60, 60000);

            _queueWatchTimers = new Timer[DataSyncQueueNum];
            for (int i = 0; i < DataSyncQueueNum; i++)
            {
                _queueWatchTimers[i] = new Timer(OnCheckRedisSyncQueue, i, 100, 100);
            }
            _threadPools = new SmartThreadPool(180 * 1000, 100, 5);
            _threadPools.Start();
            _enableWriteToDb = setting.EnableWriteToDb;
            if (_enableWriteToDb)
            {
                int sqlSyncInterval = ConfigUtils.GetSetting("Game.Cache.UpdateDbInterval", 300 * 1000);
                _sqlWaitTimers = new Timer[SqlWaitSyncQueueNum];
                for (int i = 0; i < SqlWaitSyncQueueNum; i++)
                {
                    _sqlWaitTimers[i] = new Timer(OnCheckSqlWaitSyncQueue, i, 100, sqlSyncInterval);
                }
                SqlStatementManager.Start();
            }
        }
Example #2
0
        public void QueueWorkItem_WhenQueueMaxLengthZero_RejectsInsteadOfQueueing()
        {
            Assert.Throws <QueueRejectedException>(() =>
            {
                var info = new STPStartInfo
                {
                    MaxQueueLength   = 0,
                    MinWorkerThreads = 2,
                    MaxWorkerThreads = 2,
                };
                var pool = new SmartThreadPool(info);
                pool.Start();

                try
                {
                    pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
                    pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
                }
                catch (QueueRejectedException e)
                {
                    throw new Exception("Caught QueueRejectedException too early: ", e);
                }

                pool.QueueWorkItem(SleepForOneSecond);
            });
        }
Example #3
0
        private void InitializeThreadPool()
        {
            int offerThreadCount = 200;

            try
            {
                string offerThread = ConfigurationManager.AppSettings["dealThread"];
                if (!string.IsNullOrEmpty(offerThread))
                {
                    int  count     = 0;
                    bool isSuccess = int.TryParse(offerThread.Trim(), out count);
                    if (isSuccess)
                    {
                        offerThreadCount = count;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex.Message, ex);
            }

            smartPool.MaxThreads = offerThreadCount;
            smartPool.MinThreads = 25;
            smartPool.Start();
        }
Example #4
0
        public void RegionLoaded(Scene scene)
        {
            if (!m_Enabled)
            {
                return;
            }

            m_EventManager = new EventManager(this);

            m_Compiler = new Compiler(this);

            m_Scene.EventManager.OnRemoveScript     += OnRemoveScript;
            m_Scene.EventManager.OnScriptReset      += OnScriptReset;
            m_Scene.EventManager.OnStartScript      += OnStartScript;
            m_Scene.EventManager.OnStopScript       += OnStopScript;
            m_Scene.EventManager.OnGetScriptRunning += OnGetScriptRunning;
            m_Scene.EventManager.OnShutdown         += OnShutdown;

            if (m_SleepTime > 0)
            {
                m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoMaintenance),
                                           new Object[] { m_SleepTime });
            }

            if (m_SaveTime > 0)
            {
                m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoBackup),
                                           new Object[] { m_SaveTime });
            }

            m_ThreadPool.Start();
        }
Example #5
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            txtLogs.Clear();
            if (File.Exists(_proxyPath) == false)
            {
                return;
            }
            _proxies = new List <string>();
            var proxies = File.ReadLines(_proxyPath);

            foreach (var proxy in proxies)
            {
                _proxies.Add(proxy.Trim());
            }
            if (_proxies.Count == 0)
            {
                return;
            }
            _tokenSource = new CancellationTokenSource();
            _token       = _tokenSource.Token;
            Running(true);
            var listClientId = txtClientIDList.Text.Trim();
            var clients      = Regex.Split(listClientId, "\n", RegexOptions.Multiline);

            _threadPool = new SmartThreadPool()
            {
                Concurrency = 1, MaxThreads = 1, MinThreads = 1
            };
            var totalClient = 0;
            var timeout     = int.Parse(numTimeout.Text);
            var proxyType   = comboProxyType.Items[comboProxyType.SelectedIndex].ToString();

            foreach (var _ in clients)
            {
                var client = _.Trim();
                if (client.Length <= 0)
                {
                    continue;
                }
                _threadPool.QueueWorkItem(DoWork, client, int.Parse(numThreads.Text), timeout, proxyType);
                totalClient++;
            }
            lbTotalProxy.Text  = _proxies.Count.ToString();
            lbTotalClient.Text = totalClient.ToString();
            new Thread(() =>
            {
                _threadPool.Start();
                _threadPool.Join();
                _threadPool.WaitForIdle();
                _threadPool.Dispose();
                _tokenSource.Dispose();
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                Running(false);
            })
            {
                IsBackground = true
            }.Start();
        }
        public void Start(int MaxThreadCount, int minThreadCount = _DefaultMinThreadCount)
        {
            lock (m_SyncRoot)
            {
                if (m_Disposed)
                {
                    throw new ObjectDisposedException(GetType().FullName);
                }

                if (m_Started)
                {
                    throw new InvalidOperationException("SmartThreadPool already started.");
                }

                STPStartInfo startInfo = new STPStartInfo();
                startInfo.MinWorkerThreads = minThreadCount;
                startInfo.MaxWorkerThreads = MaxThreadCount;
                startInfo.IdleTimeout      = 20000; // After 20 seconds, a thread counts as an idle one
                startInfo.EnableLocalPerformanceCounters = true;
                startInfo.ThreadPoolName = "Smart Threadpool";
                m_SmartThreadPool        = new SmartThreadPool(startInfo);
                m_SmartThreadPool.Start();
                statisticsTimer = new Timer(new TimerCallback(StatisticsTimer), null, 5000, 120000);
                m_Started       = true;
            }
        }
Example #7
0
        public void QueueWorkItem_WhenMaxIsSet_ThrowsExceptionWhenHit()
        {
            Assert.Throws <QueueRejectedException>(() =>
            {
                var info = new STPStartInfo
                {
                    MaxQueueLength   = 1,
                    MinWorkerThreads = 1,
                    MaxWorkerThreads = 1,
                };
                var pool = new SmartThreadPool(info);
                pool.Start();

                try
                {
                    pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
                    pool.QueueWorkItem(SleepForOneSecond); // No waiters available, pool at max threads. Queued.
                }
                catch (QueueRejectedException e)
                {
                    throw new Exception("Caught QueueRejectedException too early: ", e);
                }

                // No waiters available, queue is at max (1). Throws.
                pool.QueueWorkItem(SleepForOneSecond);
            });
        }
        public void Initialise(IConfigSource config)
        {
            m_proxyurl     = config.Configs["Startup"].GetString("HttpProxy");
            m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions");

            HttpRequestClass.HttpBodyMaxLenMAX = config.Configs["Network"].GetInt("HttpBodyMaxLenMAX", 16384);


            m_outboundUrlFilter = new OutboundUrlFilter("Script HTTP request module", config);
            int maxThreads = 15;

            IConfig httpConfig = config.Configs["HttpRequestModule"];

            if (httpConfig != null)
            {
                maxThreads = httpConfig.GetInt("MaxPoolThreads", maxThreads);
            }

            m_pendingRequests = new Dictionary <UUID, HttpRequestClass>();

            // First instance sets this up for all sims
            if (ThreadPool == null)
            {
                STPStartInfo startInfo = new STPStartInfo();
                startInfo.IdleTimeout      = 20000;
                startInfo.MaxWorkerThreads = maxThreads;
                startInfo.MinWorkerThreads = 1;
                startInfo.ThreadPriority   = ThreadPriority.BelowNormal;
                startInfo.StartSuspended   = true;
                startInfo.ThreadPoolName   = "ScriptsHttpReq";

                ThreadPool = new SmartThreadPool(startInfo);
                ThreadPool.Start();
            }
        }
Example #9
0
        public void STPAndWIGStartSuspended()
        {
            STPStartInfo stpStartInfo = new STPStartInfo();

            stpStartInfo.StartSuspended = true;

            SmartThreadPool stp = new SmartThreadPool(stpStartInfo);

            WIGStartInfo wigStartInfo = new WIGStartInfo();

            wigStartInfo.StartSuspended = true;

            IWorkItemsGroup wig = stp.CreateWorkItemsGroup(10, wigStartInfo);

            wig.QueueWorkItem(new WorkItemCallback(this.DoWork));

            Assert.IsFalse(wig.WaitForIdle(200));

            wig.Start();

            Assert.IsFalse(wig.WaitForIdle(200));

            stp.Start();

            Assert.IsTrue(wig.WaitForIdle(5000), "WIG is not idle");
            Assert.IsTrue(stp.WaitForIdle(5000), "STP is not idle");
        }
        public void Start()
        {
            m_running = true;
            m_threadPool.Start();
            //startup worker threads
            for (uint i = 0; i < m_WorkerThreadCount; i++)
            {
                m_workerThreads[i]
                    = WorkManager.StartThread(
                          PoolWorkerJob,
                          string.Format("PollServiceWorkerThread {0}:{1}", i, m_server.Port),
                          ThreadPriority.Normal,
                          false,
                          false,
                          null,
                          int.MaxValue);
            }

            m_retrysThread = WorkManager.StartThread(
                this.CheckRetries,
                string.Format("PollServiceWatcherThread:{0}", m_server.Port),
                ThreadPriority.Normal,
                false,
                true,
                null,
                1000 * 60 * 10);
        }
Example #11
0
        // Upload the difference in the chunkLists
        private void UploadChunkList(ref List <ChunkInfo> chunkList_toUpload, string filePath, string blobName)
        {
            // SmartThreadPool threadPool = new SmartThreadPool();
            //  threadPool.MaxThreads = MaxConcurrentUploadThreads;

            if (logger != null)
            {
                logger.Log("Start UploadChunkList Create and Queue Threads");
            }
            SmartThreadPool threadPool = new SmartThreadPool();

            threadPool.MaxThreads = MaxConcurrentUploadThreads;

            foreach (ChunkInfo chunk in chunkList_toUpload)
            {
                ChunkInfo       chunkToUpload = chunk;
                IWorkItemResult wir1          = threadPool.QueueWorkItem(new WorkItemCallback(this.UploadChunk_Worker), new Tuple <string, string, ChunkInfo>(filePath, blobName, chunkToUpload));
                //    UploadChunk(filePath, blobName, ref chunkToUpload);
            }
            threadPool.Start();
            threadPool.WaitForIdle();
            threadPool.Shutdown();
            if (logger != null)
            {
                logger.Log("End UploadChunkList Create and Queue Threads");
            }
        }
Example #12
0
        /// <summary>
        /// Start
        /// </summary>
        public static void Start()
        {
            TraceLog.ReleaseWriteDebug("Sql write queue start init...");
            MessageQueueSection section = GetSection();

            SlaveMessageQueue = section.SlaveMessageQueue;
            if (_queueWatchTimers != null && _queueWatchTimers.Length != section.SqlSyncQueueNum)
            {
                foreach (var timer in _queueWatchTimers)
                {
                    try
                    {
                        timer.Dispose();
                    }
                    catch (Exception ex)
                    {
                        TraceLog.WriteError("Sql write queue stop error:{0}", ex);
                    }
                }
                _queueWatchTimers = null;
            }
            if (_queueWatchTimers == null)
            {
                _isWatchWorking   = new int[section.SqlSyncQueueNum];
                _queueWatchTimers = new Timer[_isWatchWorking.Length];
                for (int i = 0; i < _queueWatchTimers.Length; i++)
                {
                    _queueWatchTimers[i] = new Timer(OnCheckSqlSyncQueue, i, 100, 100);
                }
                _threadPools = new SmartThreadPool(180 * 1000, 100, 5);
                _threadPools.Start();
            }
        }
        public void Start()
        {
            try
            {
                string queueSizeCheckMilliseconds = ConfigurationManager.AppSettings["QueueSizeCheckIntervalInMilliseconds"];
                _keepTabsOnQueueSizeCounter =
                    new System.Timers.Timer((queueSizeCheckMilliseconds == null) ? _queueSizeCheckMilliseconds : Convert.ToInt32(queueSizeCheckMilliseconds));
                _keepTabsOnQueueSizeCounter.Start();

                //you’ll want to use a MessageReadPropertyFilter in order to basically filter out all the data to keep the foot print small.
                _countFilter.AdministrationQueue = false;
                _countFilter.ArrivedTime         = false;
                _countFilter.CorrelationId       = false;
                _countFilter.Priority            = false;
                _countFilter.ResponseQueue       = false;
                _countFilter.SentTime            = false;
                _countFilter.Body  = false;
                _countFilter.Label = false;
                _countFilter.Id    = false;

                _keepTabsOnQueueSizeCounter.Elapsed += new System.Timers.ElapsedEventHandler(_keepTabsOnQueueSizeCounter_Elapsed);

                string minThreads = ConfigurationManager.AppSettings["MinThreads"];
                string maxThreads = ConfigurationManager.AppSettings["MaxThreads"];

                //don't forget to start the threadpool...
                _tp.MinThreads = minThreads == null ? _minThreads : Convert.ToInt32(minThreads);
                _tp.MaxThreads = maxThreads == null ? _maxThreads : Convert.ToInt32(maxThreads);

                _tp.Start();

                string messageQueueSetting = ConfigurationManager.AppSettings["queueName"];
                _queueName = messageQueueSetting == null ? null : messageQueueSetting;

                if (_queueName == null)
                {
                    throw new ApplicationException("No valid queueName setting in the Configuration File");
                }

                // Create a transaction queue using System.Messaging API
                if (!MessageQueue.Exists(_queueName))
                {
                    MessageQueue.Create(_queueName, true);
                }

                //Connect to the queue
                MessageQueue Queue = new MessageQueue(_queueName);

                System.Messaging.MessageQueue.EnableConnectionCache = false;
                watchQueueDelegate dlgt = new watchQueueDelegate(watchQueue);
                IAsyncResult       ar   = dlgt.BeginInvoke(_queueName, new AsyncCallback(watchQueueCallback), dlgt);
                _log.Debug("AuditMSMQProcessingService is running");
            }
            catch (Exception ex)
            {
                _log.Fatal(ex);
            }
        }
Example #14
0
 public void test()
 {
     smartThreadPool.Start();
     for (int i = 0; i < 1000; i++)
     {
         smartThreadPool.QueueWorkItem(handler, "序号" + i.ToString() + ";");
     }
     smartThreadPool.Shutdown();
 }
Example #15
0
 private void Start()
 {
     _workItemsGenerated = 0;
     UpdateControls(true);
     _smartThreadPool.Start();
     _wig1.Start();
     _wig2.Start();
     _wig3.Start();
 }
 /// <summary>
 /// Start
 /// </summary>
 public static void Start()
 {
     _queueWatchTimers = new Timer[SqlSyncQueueNum];
     for (int i = 0; i < SqlSyncQueueNum; i++)
     {
         _queueWatchTimers[i] = new Timer(OnCheckSqlSyncQueue, i, 100, 100);
     }
     _threadPools = new SmartThreadPool(180 * 1000, 100, 5);
     _threadPools.Start();
 }
Example #17
0
        public void StpStartInfo_WithZeroMaxQueueLength_IsAllowed()
        {
            var info = new STPStartInfo
            {
                MaxQueueLength = 0,
            };
            var pool = new SmartThreadPool(info);

            pool.Start();
            Assert.True(0 == pool.STPStartInfo.MaxQueueLength);
        }
Example #18
0
        private void RunConversionPool()
        {
            results.Clear();
            convertPool = SetupSmartThreadPool(settings.ConversionPoolThreads);
            addConversionsToQueue();
            convertPool.Start();
            bool converted = SmartThreadPool.WaitAll(results.ToArray());

            convertPool.Shutdown();

            WriteStatus("conversion Pool completed, success = " + converted.ToString());
        }
Example #19
0
        /// <summary>
        /// Start
        /// </summary>
        /// <param name="setting"></param>
        /// <param name="serializer"></param>
        public static void Start(CacheSetting setting, ICacheSerializer serializer)
        {
            _serializer        = serializer;
            _entityQueueTimer  = new Timer(OnEntitySyncQueue, null, 60, 500);
            _entityQueueWacher = new Timer(CheckEntityQueue, null, 60, 60000);
            MessageQueueSection section = GetSection();

            InitRedisQueue(section);
            InitSqlQueue(section);
            _threadPools = new SmartThreadPool(180 * 1000, 100, 5);
            _threadPools.Start();
        }
Example #20
0
        /// <summary>
        /// Starts the tasks execution.
        /// </summary>
        /// <returns>If has reach the timeout false, otherwise true.</returns>
        public override bool Start()
        {
            base.Start();
            m_threadPool = new SmartThreadPool();

            try
            {
                m_threadPool.MinThreads = MinThreads;
                m_threadPool.MaxThreads = MaxThreads;
                var workItemResults = new IWorkItemResult[Tasks.Count];

                for (int i = 0; i < Tasks.Count; i++)
                {
                    var t = Tasks[i];
                    workItemResults[i] = m_threadPool.QueueWorkItem(new WorkItemCallback(Run), t);
                }

                m_threadPool.Start();

                // Timeout was reach?
                if (!m_threadPool.WaitForIdle(Timeout.TotalMilliseconds > int.MaxValue ? int.MaxValue : Convert.ToInt32(Timeout.TotalMilliseconds)))
                {
                    if (m_threadPool.IsShuttingdown)
                    {
                        return(true);
                    }
                    else
                    {
                        m_threadPool.Cancel(true);
                        return(false);
                    }
                }

                foreach (var wi in workItemResults)
                {
                    Exception ex;
                    wi.GetResult(out ex);

                    if (ex != null)
                    {
                        throw ex;
                    }
                }

                return(true);
            }
            finally
            {
                m_threadPool.Shutdown(true, 1000);
                m_threadPool.Dispose();
                IsRunning = false;
            }
        }
        public void Initialise(IConfigSource config)
        {
            m_proxyurl     = config.Configs["Startup"].GetString("HttpProxy");
            m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions");

            HttpRequestClass.HttpBodyMaxLenMAX = config.Configs["Network"].GetInt("HttpBodyMaxLenMAX", 16384);

            m_outboundUrlFilter = new OutboundUrlFilter("Script HTTP request module", config);

            int     maxThreads = 8;
            IConfig httpConfig = config.Configs["ScriptsHttpRequestModule"];

            if (httpConfig != null)
            {
                maxThreads        = httpConfig.GetInt("MaxPoolThreads", maxThreads);
                m_primBurst       = httpConfig.GetFloat("PrimRequestsBurst", m_primBurst);
                m_primPerSec      = httpConfig.GetFloat("PrimRequestsPerSec", m_primPerSec);
                m_primOwnerBurst  = httpConfig.GetFloat("PrimOwnerRequestsBurst", m_primOwnerBurst);
                m_primOwnerPerSec = httpConfig.GetFloat("PrimOwnerRequestsPerSec", m_primOwnerPerSec);
                m_httpTimeout     = httpConfig.GetInt("RequestsTimeOut", m_httpTimeout);
                if (m_httpTimeout > 60000)
                {
                    m_httpTimeout = 60000;
                }
                else if (m_httpTimeout < 200)
                {
                    m_httpTimeout = 200;
                }
            }

            m_pendingRequests       = new Dictionary <UUID, HttpRequestClass>();
            m_CompletedRequests     = new ConcurrentQueue <HttpRequestClass>();
            m_RequestsThrottle      = new ConcurrentDictionary <uint, ThrottleData>();
            m_OwnerRequestsThrottle = new ConcurrentDictionary <UUID, ThrottleData>();

            // First instance sets this up for all sims
            if (ThreadPool == null)
            {
                STPStartInfo startInfo = new STPStartInfo()
                {
                    IdleTimeout      = 2000,
                    MaxWorkerThreads = maxThreads,
                    MinWorkerThreads = 0,
                    ThreadPriority   = ThreadPriority.Normal,
                    StartSuspended   = true,
                    ThreadPoolName   = "ScriptsHttpReq"
                };

                ThreadPool = new SmartThreadPool(startInfo);
                ThreadPool.Start();
            }
        }
Example #22
0
        static ScreenClientHandler()
        {
            smartThreadPool = new SmartThreadPool();
            smartThreadPool.Start();

            int start = 65, end = 90;

            while (start <= end)
            {
                listIndex.Add(((char)start).ToString());
                start++;
            }
        }
Example #23
0
        public void Start()
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                _pool.Start();
            }
            finally
            {
                _stats.Elapsed(StatsPrefix + " Start", null, stopwatch.Elapsed);
            }
        }
        public static void RunThreads(Action <byte[], byte[], int> function, List <byte[]> arrayList, byte[] arrayRgbColorBytes, int threadsAmount)
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool(60 * 1000, threadsAmount, threadsAmount);


            foreach (var byteArray in arrayList)
            {
                smartThreadPool.QueueWorkItem(function, byteArray, arrayRgbColorBytes, byteArray.Length);
            }

            smartThreadPool.Start();
            smartThreadPool.WaitForIdle();
            smartThreadPool.Shutdown();
        }
Example #25
0
        public void QueueWorkItem_WhenMaxIsNull_Queues()
        {
            var info = new STPStartInfo
            {
                MaxQueueLength = null,
            };
            var pool = new SmartThreadPool(info);

            pool.Start();
            var workItem = pool.QueueWorkItem <object>(ReturnNull);

            // If rejected, an exception would have been thrown instead.
            Assert.IsTrue(workItem.GetResult() == null);
        }
Example #26
0
        public void SetMaxQueueLength_FromNonZeroValueToZero_DisablesQueueing()
        {
            Assert.Throws <QueueRejectedException>(() =>
            {
                var info = new STPStartInfo
                {
                    MinWorkerThreads = 1,
                    MaxWorkerThreads = 1,
                    MaxQueueLength   = 1,
                };

                var pool = new SmartThreadPool(info);
                pool.Start();

                try
                {
                    pool.QueueWorkItem(SleepForOneSecond); // Picked up by waiter.
                    pool.QueueWorkItem(SleepForOneSecond); // Queued.
                }
                catch (QueueRejectedException e)
                {
                    throw new Exception("Caught QueueRejectedException too early: ", e);
                }

                try
                {
                    pool.QueueWorkItem(SleepForOneSecond);
                }
                catch (QueueRejectedException)
                {
                    // Expected
                    Assert.True(true);
                }

                pool.MaxQueueLength = 0;
                Thread.Sleep(2100); // Let the work items complete.

                try
                {
                    pool.QueueWorkItem(SleepForOneSecond); // Picked up by waiter.
                }
                catch (QueueRejectedException e)
                {
                    throw new Exception("Caught QueueRejectedException too early: ", e);
                }

                pool.QueueWorkItem(SleepForOneSecond); // Rejected (max queue length is zero).
            });
        }
Example #27
0
        private void RunDownloadPool(WorkType work)
        {
            //Setup downloadPool
            downloadPool = SetupSmartThreadPool(settings.DownloadPoolThreads);

            //Select the items to add to the queue
            addDownloadTasksToQueue(work);
            downloadPool.Start();

            bool success = SmartThreadPool.WaitAll(results.ToArray());

            downloadPool.Shutdown();

            WriteStatus("Download Pool Completed, succeeded = " + success.ToString());
        }
Example #28
0
        public Dataserver(AsyncCommandManager CmdManager)
        {
            m_CmdManager = CmdManager;

            STPStartInfo startInfo = new STPStartInfo();

            startInfo.ThreadPoolName   = "ScriptV";
            startInfo.IdleTimeout      = 1000;
            startInfo.MaxWorkerThreads = 4;
            startInfo.MinWorkerThreads = 0;
            startInfo.ThreadPriority   = ThreadPriority.Normal;
            startInfo.StartSuspended   = true;

            m_ThreadPool = new SmartThreadPool(startInfo);
            m_ThreadPool.Start();
        }
Example #29
0
        public void StartSuspended()
        {
            STPStartInfo stpStartInfo = new STPStartInfo();

            stpStartInfo.StartSuspended = true;

            SmartThreadPool stp = new SmartThreadPool(stpStartInfo);

            stp.QueueWorkItem(new WorkItemCallback(this.DoWork));

            Assert.IsFalse(stp.WaitForIdle(200));

            stp.Start();

            Assert.IsTrue(stp.WaitForIdle(200));
        }
Example #30
0
        /// <summary>
        ///
        /// </summary>
        protected GameSocketHost()
        {
            ActionDispatcher = new ActionDispatcher();
            int        port          = GameEnvironment.Setting.GamePort;
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, port);

            int maxConnections = ConfigUtils.GetSetting("MaxConnections", 10000);
            int backlog        = ConfigUtils.GetSetting("Backlog", 1000);
            int maxAcceptOps   = ConfigUtils.GetSetting("MaxAcceptOps", 1000);
            int bufferSize     = ConfigUtils.GetSetting("BufferSize", 8192);
            int expireInterval = ConfigUtils.GetSetting("ExpireInterval", 600) * 1000;
            int expireTime     = ConfigUtils.GetSetting("ExpireTime", 3600) * 1000;

            threadPool = new SmartThreadPool(180 * 1000, 100, 5);
            threadPool.Start();

            var socketSettings = new SocketSettings(maxConnections, backlog, maxAcceptOps, bufferSize, localEndPoint, expireInterval, expireTime);

            socketLintener = new SocketListener(socketSettings);
            socketLintener.DataReceived += new ConnectionEventHandler(socketLintener_DataReceived);
            socketLintener.Connected    += new ConnectionEventHandler(socketLintener_OnConnectCompleted);
            socketLintener.Disconnected += new ConnectionEventHandler(socketLintener_Disconnected);


            httpListener = new HttpListener();
            var httpHost = ConfigUtils.GetSetting("Game.Http.Host");
            var httpPort = ConfigUtils.GetSetting("Game.Http.Port", 80);
            var httpName = ConfigUtils.GetSetting("Game.Http.Name", "Service.aspx");

            if (!string.IsNullOrEmpty(httpHost))
            {
                EnableHttp = true;
                var hosts = httpHost.Split(',');
                foreach (var host in hosts)
                {
                    string address = host.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)
                                         ? host
                                         : "http://" + host;
                    httpListener.Prefixes.Add(string.Format("{0}:{1}/{2}/", address, httpPort, httpName));
                }
            }
            Interlocked.Exchange(ref _runningQueue, 1);
            queueProcessThread = new Thread(ProcessQueue);
            queueProcessThread.Start();
            _LockedQueueChecker = new Timer(LockedQueueChecker, null, 100, 100);
        }