Esempio n. 1
0
        public Gateway()
        {
            HttpServer        = new HttpApiServer();
            Routes            = new Routes.RouteCenter(this);
            Agents            = new Servers.ServerCenter(this);
            this.PluginCenter = new PluginCenter(this);
            this.Pluginer     = new Pluginer(this, null);
            //HttpServer.Options.IOQueueEnabled = true;

            Statistics.Server     = "Gateway";
            AgentMaxSocketError   = 3;
            MaxStatsUrls          = 2000;
            AgentMaxConnection    = 200;
            AgentRequestQueueSize = 2000;
            ThreadQueues          = (Environment.ProcessorCount / 2);
            if (ThreadQueues == 0)
            {
                ThreadQueues = 1;
            }

            AgentBufferSize     = 1024 * 8;
            AgentBufferPoolSize = 1024 * 200;
            GatewayQueueSize    = Environment.ProcessorCount * 500;
            InstanceID          = Guid.NewGuid().ToString("N");
        }
Esempio n. 2
0
 public Gateway()
 {
     HttpServer = new HttpApiServer();
     HttpServer.Options.Port = 8080;
     Filters = new Filters.FilterCenter(this);
     Routes  = new Routes.RouteCenter(this);
     Agents  = new Servers.ServerCenter(this);
 }
Esempio n. 3
0
 public void Remove(string host)
 {
     host = ServerCenter.GetHost(host);
     for (int i = 0; i < mServers.Count; i++)
     {
         if (mServers[i].Agent.Uri.ToString() == host)
         {
             ulong id = mServers[i].ID;
             mServers.RemoveAt(i);
             if (mServers.Count > 0)
             {
                 RefreshWeightTable();
             }
             mServerID.Enqueue(id);
             Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway {Url} route remove server {host} success");
             return;
         }
     }
 }
Esempio n. 4
0
 public Gateway()
 {
     HttpServer            = new HttpApiServer();
     Routes                = new Routes.RouteCenter(this);
     Agents                = new Servers.ServerCenter(this);
     this.PluginCenter     = new PluginCenter(this);
     this.Pluginer         = new Pluginer(this, null);
     Statistics.Server     = "Gateway";
     AgentMaxSocketError   = 3;
     MaxStatsUrls          = 20000;
     AgentMaxConnection    = 200;
     AgentRequestQueueSize = 2000;
     ThreadQueues          = (Environment.ProcessorCount / 2);
     if (ThreadQueues == 0)
     {
         ThreadQueues = 1;
     }
     GatewayQueueSize = Environment.ProcessorCount * 100;
     InstanceID       = Guid.NewGuid().ToString("N");
     GATEWAY_VERSION  = $"BeetleX/Bumblebee[{GetType().Assembly.GetName().Version.ToString()}]";
 }
Esempio n. 5
0
        public void NewOrModify(string host, int weight, int maxRps)
        {
            host = ServerCenter.GetHost(host);
            if (weight > 10)
            {
                weight = 10;
            }
            if (weight < 0)
            {
                weight = 0;
            }
            var item = mServers.Find(i => i.Agent.Uri.ToString() == host);

            if (item != null)
            {
                item.Weight = weight;
                item.MaxRPS = maxRps;
                Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway {Url} route update server [{host}] weight [{weight}] max rps [{maxRps}] success");
            }
            else
            {
                var agent = Gateway.Agents.Get(host);
                if (agent == null)
                {
                    Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway {Url} route add server error {host} server not found!");
                    return;
                }
                else
                {
                    UrlServerInfo serverItem = new UrlServerInfo(Url, agent);
                    mServerID.TryDequeue(out ulong id);
                    serverItem.ID     = id;
                    serverItem.Weight = weight;
                    serverItem.MaxRPS = maxRps;
                    mServers.Add(serverItem);
                    Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway {Url} route add server [{host}] weight [{weight}] max rps [{maxRps}] success");
                }
            }
            RefreshWeightTable();
        }
Esempio n. 6
0
 public Gateway()
 {
     BufferPool.BUFFER_SIZE   = BufferSize;
     BufferPool.POOL_MAX_SIZE = PoolMaxSize;
     HttpServer            = new HttpApiServer();
     Routes                = new Routes.RouteCenter(this);
     Agents                = new Servers.ServerCenter(this);
     this.PluginCenter     = new PluginCenter(this);
     this.Pluginer         = new Pluginer(this, null);
     Statistics.Server     = "Gateway";
     AgentMaxSocketError   = 3;
     MaxStatsUrls          = 2000;
     AgentMaxConnection    = 200;
     AgentRequestQueueSize = 2000;
     ThreadQueues          = (Environment.ProcessorCount / 2);
     if (ThreadQueues == 0)
     {
         ThreadQueues = 1;
     }
     GatewayQueueSize = Environment.ProcessorCount * 500;
     InstanceID       = Guid.NewGuid().ToString("N");
 }
Esempio n. 7
0
        public void NewOrModify(string host, int weight, int maxRps, bool standby)
        {
            host = ServerCenter.GetHost(host);
            if (weight > 10)
            {
                weight = 10;
            }
            if (weight < 0)
            {
                weight = 0;
            }
            var item = mServers.Find(i => i.Agent.Uri.ToString() == host);

            if (item != null)
            {
                item.Weight  = weight;
                item.MaxRPS  = maxRps;
                item.Standby = standby;
                Gateway.HttpServer.GetLog(LogType.Info)?.Log(BeetleX.EventArgs.LogType.Info, $"gateway {Url} route update server [{host}] weight [{weight}] max rps [{maxRps}] success");
            }
            else
            {
                var agent = Gateway.Agents.Get(host);
                if (agent == null)
                {
                    Gateway.Agents.SetServer(host, Gateway.AgentMaxConnection);
                    agent = Gateway.Agents.Get(host);
                }
                UrlServerInfo serverItem = new UrlServerInfo(Url, agent);
                mServerID.TryDequeue(out ulong id);
                serverItem.ID      = id;
                serverItem.Weight  = weight;
                serverItem.MaxRPS  = maxRps;
                serverItem.Standby = standby;
                mServers.Add(serverItem);
                Gateway.HttpServer.GetLog(LogType.Info)?.Log(BeetleX.EventArgs.LogType.Info, $"gateway {Url} route add server [{host}] weight [{weight}] max rps [{maxRps}] success");
            }
            RefreshWeightTable();
        }
Esempio n. 8
0
 public Gateway()
 {
     HttpServer            = new HttpApiServer();
     Routes                = new Routes.RouteCenter(this);
     Agents                = new Servers.ServerCenter(this);
     this.PluginCenter     = new PluginCenter(this);
     this.Pluginer         = new Pluginer(this, null);
     Statistics.Server     = "Gateway";
     AgentMaxSocketError   = 3;
     MaxStatsUrls          = 20000;
     AgentMaxConnection    = 500;
     AgentRequestQueueSize = 500;
     ThreadQueues          = (Environment.ProcessorCount / 2);
     if (ThreadQueues == 0)
     {
         ThreadQueues = 1;
     }
     GatewayQueueSize = Environment.ProcessorCount * 100;
     InstanceID       = Guid.NewGuid().ToString("N");
     GATEWAY_VERSION  = $"beetlex.io";
     TimeoutFactory   = new TimeoutFactory(this);
 }
Esempio n. 9
0
        public Gateway()
        {
            HttpServer = new HttpApiServer();
            Filters    = new Filters.FilterCenter(this);
            Routes     = new Routes.RouteCenter(this);
            Agents     = new Servers.ServerCenter(this);
            HttpServer.Options.IOQueueEnabled = true;
            HttpServer.Options.UrlIgnoreCase  = false;
            AgentMaxSocketError     = 5;
            MaxStatsUrls            = 1000;
            AgentMaxConnection      = 300;
            AgentRequestQueueLength = 2000;
            int threads = (Environment.ProcessorCount / 2);

            if (threads == 0)
            {
                threads = 1;
            }
            multiThreadDispatcher = new BeetleX.Dispatchs.DispatchCenter <RequestAgent>(OnExecuteRequest,
                                                                                        Math.Min(threads, 16));
            AgentBufferSize     = 1024 * 8;
            AgentBufferPoolSize = 1024 * 200;
        }