private void TimerFired(object state) { int requestsProcessed = Interlocked.Exchange(ref _requestsProcessed, 0); int maxAccepts, maxRequests; _server.GetRequestProcessingLimits(out maxAccepts, out maxRequests); Console.WriteLine("Active/MaxAccepts:" + maxAccepts + "/" + (int)_currentMaxAccepts + ", Active/MaxRequests:" + maxRequests + "/" + _currentMaxRequests + ", Requests/1sec: " + requestsProcessed); _server.SetRequestProcessingLimits((int)(_currentMaxAccepts += 0.1), _currentMaxRequests); }
// This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public static void ConfigureApp(IAppBuilder appBuilder) { // Configure Web API for self-host. //HttpConfiguration config = new HttpConfiguration(); //config.Routes.MapHttpRoute( // name: "DefaultApi", // routeTemplate: "api/{controller}/{id}", // defaults: new { id = RouteParameter.Optional } //); //appBuilder.UseWebApi(config); //Connection setup OwinHttpListener listener = (OwinHttpListener)appBuilder.Properties[typeof(OwinHttpListener).FullName]; int maxAccepts = 0; int maxRequests = 0; listener.GetRequestProcessingLimits(out maxAccepts, out maxRequests); listener.SetRequestProcessingLimits(maxAccepts * 8, maxRequests); // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); //config.Services.Replace(typeof(IExceptionHandler), new CustomExceptionHanlder()); config.MapHttpAttributeRoutes(); config.Formatters.XmlFormatter.SupportedMediaTypes.Clear(); config.Formatters.JsonFormatter.UseDataContractJsonSerializer = false; FormatterConfig.ConfigureFormatters(config.Formatters); RouteConfig.RegisterRoutes(config.Routes); appBuilder.UseWebApi(config); //Then do SignalR //GlobalHost.HubPipeline.AddModule(new ErrorHandlingPipelineModule()); appBuilder.MapSignalR(); var fabricProtData = new Lazy <FabricProtectedData>(() => new FabricProtectedData()); GlobalHost.DependencyResolver.Register(typeof(Microsoft.AspNet.SignalR.Infrastructure.IProtectedData), () => fabricProtData.Value); //And init config.EnsureInitialized(); //ConnectionHandler.Instance.MapContext(GlobalHost.ConnectionManager.GetHubContext<InterfaceHub>().Clients); }
public static void Main(string[] args) { var configurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; XmlConfigurator.ConfigureAndWatch(new FileInfo(configurationFile)); SetConsoleCtrlHandler(ConsoleCtrlCheck, true); var managerName = ConfigurationManager.AppSettings["ManagerName"]; var baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]); var managerAddress = baseAddress.Scheme + "://+:" + baseAddress.Port + "/"; AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload; WhoAmI = "[MANAGER CONSOLE HOST ( " + managerName + ", " + managerAddress + " )," + Environment.MachineName.ToUpper() + "]"; Logger.InfoWithLineNumber(WhoAmI + " : started."); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; var managerConfiguration = new ManagerConfiguration( ConfigurationManager.ConnectionStrings["ManagerConnectionString"].ConnectionString, ConfigurationManager.AppSettings["route"], int.Parse(ConfigurationManager.AppSettings["AllowedNodeDownTimeSeconds"]), int.Parse(ConfigurationManager.AppSettings["CheckNewJobIntervalSeconds"]), int.Parse(ConfigurationManager.AppSettings["purgeJobsBatchSize"]), int.Parse(ConfigurationManager.AppSettings["purgeJobsIntervalHours"]), int.Parse(ConfigurationManager.AppSettings["PurgeJobsOlderThanHours"]), int.Parse(ConfigurationManager.AppSettings["PurgeNodesIntervalHours"])); var container = new ContainerBuilder().Build(); var config = new HttpConfiguration(); using (WebApp.Start(managerAddress, appBuilder => { string owinListenerName = "Microsoft.Owin.Host.HttpListener.OwinHttpListener"; OwinHttpListener owinListener = (OwinHttpListener)appBuilder.Properties[owinListenerName]; int maxAccepts; int maxRequests; owinListener.GetRequestProcessingLimits(out maxAccepts, out maxRequests); owinListener.SetRequestQueueLimit(int.MaxValue); owinListener.SetRequestProcessingLimits(int.MaxValue, int.MaxValue); appBuilder.UseAutofacMiddleware(container); // Configure Web API for self-host. appBuilder.UseStardustManager(managerConfiguration, container); appBuilder.UseAutofacWebApi(config); appBuilder.UseWebApi(config); })) { Logger.InfoWithLineNumber(WhoAmI + ": Started listening on port : ( " + baseAddress + " )"); QuitEvent.WaitOne(); } }
public void Configuration(IAppBuilder app) { if (app.Properties.ContainsKey("Microsoft.Owin.Host.HttpListener.OwinHttpListener")) { Logger.Info("configuring server environment"); OwinHttpListener listener = (OwinHttpListener)app.Properties["Microsoft.Owin.Host.HttpListener.OwinHttpListener"]; int maxAccepts, maxRequests; listener.GetRequestProcessingLimits(out maxAccepts, out maxRequests); listener.SetRequestQueueLimit(int.Parse(ConfigurationManager.AppSettings["Owin.RequestQueueLimit"])); listener.SetRequestProcessingLimits(int.Parse(ConfigurationManager.AppSettings["Owin.MaxAccepts"]), int.Parse(ConfigurationManager.AppSettings["Owin.MaxRequests"])); app.Properties["Microsoft.Owin.Host.HttpListener.OwinHttpListener"] = listener; } else { Logger.Warn("key {0} not found. Will revert to default values.", "Microsoft.Owin.Host.HttpListener.OwinHttpListener"); } app.AttachAuthenticationModules(); var config = new HttpConfiguration(); config.AttachDelegatingHandlers(); config.AttachMediaFormatters(); config.Services.Replace(typeof(IAssembliesResolver), new SidekickHttpAssemblyResolver()); config.AttachSwagger(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); config.Formatters.XmlFormatter.UseXmlSerializer = true; config.MapHttpAttributeRoutes(); config.EnsureInitialized(); app.UseCors(CorsOptions.AllowAll); SidekickEventsManager.Start(); app.MapSignalR(); EventhandlerModules = new List <IEventhandlerModule>(); LoadEventHandlers(); app.UseWebApi(config); }