private void Init(ServerSetting serverSetting) { this.bufferManager.InitBuffer(); SocketAsyncEventArgs eventArgObjectForPool; for (int i = 0; i < serverSetting.maxSimultaneousConnectOps; i++) { eventArgObjectForPool = new SocketAsyncEventArgs(); eventArgObjectForPool.Completed += new EventHandler <SocketAsyncEventArgs>(AcceptEventArg_Completed); this.poolOfAcceptEventArgs.Push(eventArgObjectForPool); } for (int i = 0; i < serverSetting.numberOfSaeaForRecSend; i++) { eventArgObjectForPool = new SocketAsyncEventArgs(); this.bufferManager.SetBuffer(eventArgObjectForPool); eventArgObjectForPool.Completed += new EventHandler <SocketAsyncEventArgs>(IO_Completed); ServerUserToken userToken = new ServerUserToken(eventArgObjectForPool.Offset, eventArgObjectForPool.Offset + serverSetting.bufferSize, serverSetting.receivePrefixLength, serverSetting.sendPrefixLength); eventArgObjectForPool.UserToken = userToken; this.poolOfRecSendEventArgs.Push(eventArgObjectForPool); } simplePerf = new SimplePerformanceCounter(true, true); }
public ClientSocketProcessor(SocketAsyncEventArgPool connectPool, SocketAsyncEventArgPool recSendPool, int maxRecSendConnection, int bufferSize, int numberMessageOfPerConnection, int prefixHandleLength, bool supportKeepAlive = false, string specialName = "") { this.poolOfConnectEventArgs = connectPool; this.poolOfRecSendEventArgs = recSendPool; this.specialNameForSimplePerf = specialName; this.simplePerf = new SimplePerformanceCounter(true, false, specialName); this.maxConnectionCount = maxRecSendConnection; this.maxConcurrentConnection = new Semaphore(maxRecSendConnection, maxRecSendConnection); this.bufferSize = bufferSize; this.numberMessagesOfPerConnection = numberMessageOfPerConnection; this.prefixHandleLength = prefixHandleLength; this.supportKeepAlive = supportKeepAlive; if (this.supportKeepAlive) { dictPoolOfHeartBeatRecSendEventArgs = new Dictionary <string, SocketAsyncEventArgPool>(); thHeartBeat = new Thread(new ThreadStart(RunHeartBeat)); thHeartBeat.IsBackground = true; thHeartBeat.Start(); } }
private static void RegisterPerfOfTimePerIO(string terminalType) { SimplePerformanceCounter simplePerf = null; if (terminalType.Equals("client")) { simplePerf = new SimplePerformanceCounter(false, false); } else if (terminalType.Equals("server")) { simplePerf = new SimplePerformanceCounter(false, true); } else { simplePerf = new SimplePerformanceCounter(false, false); } CustomPerformanceCounter.PerformanceCounterManager pfm = new CustomPerformanceCounter.PerformanceCounterManager(simplePerf.CategoryName); Dictionary <string, PerformanceCounterType> dictPerfInfo = new Dictionary <string, PerformanceCounterType>(); if (terminalType.Equals("client") || terminalType.Equals("all")) { dictPerfInfo.Add(simplePerf.ClientConcurrentConnectionCounterName, PerformanceCounterType.NumberOfItems32); dictPerfInfo.Add(simplePerf.ClientResuseConnectionCounterName, PerformanceCounterType.NumberOfItems32); dictPerfInfo.Add(simplePerf.ClientIdleConnectionCounterName, PerformanceCounterType.NumberOfItems32); dictPerfInfo.Add(simplePerf.ClientRequestSuccessCounterName, PerformanceCounterType.RateOfCountsPerSecond32); dictPerfInfo.Add(simplePerf.ClientRequestFailCounterName, PerformanceCounterType.RateOfCountsPerSecond32); dictPerfInfo.Add(simplePerf.ClientRequestTotalCounterName, PerformanceCounterType.RateOfCountsPerSecond32); } if (terminalType.Equals("server") || terminalType.Equals("all")) { if (terminalType.Equals("all")) { simplePerf = new SimplePerformanceCounter(false, true); } dictPerfInfo.Add(simplePerf.ServerConcurrentConnectionCounterName, PerformanceCounterType.NumberOfItems32); } bool result = pfm.CreatePerformanceCounter(dictPerfInfo); if (result) { Console.WriteLine("register success!"); } else { Console.WriteLine("register failed!"); } }
private SimplePerformanceCounter GetSimplePerf() { if (this.simplePerf == null) { lock (this) { if (this.simplePerf == null) { this.simplePerf = new SimplePerformanceCounter(true, true); if (this.simplePerf == null) { throw new ArgumentNullException("simplePerf", "renew server simpPerf instance failed!"); } } } } return(this.simplePerf); }
internal SimplePerformanceCounter GetSimplePerf() { if (this.simplePerf == null) { lock (this) { if (this.simplePerf == null) { this.simplePerf = new SimplePerformanceCounter(true, false, specialNameForSimplePerf); if (this.simplePerf == null) { throw new ArgumentNullException("simplePerf", "renew client simplePerf instance failed!"); } } } } return(this.simplePerf); }