A hierarchical token bucket for bandwidth throttling. See http://en.wikipedia.org/wiki/Token_bucket for more information
Exemplo n.º 1
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="parent">Parent bucket if this is a child bucket, or
 /// null if this is a root bucket</param>
 /// <param name="maxBurst">Maximum size of the bucket in bytes, or
 /// zero if this bucket has no maximum capacity</param>
 /// <param name="dripRate">Rate that the bucket fills, in bytes per
 /// second. If zero, the bucket always remains full</param>
 public TokenBucket(TokenBucket parent, int maxBurst, int dripRate)
 {
     this.parent = parent;
     MaxBurst = maxBurst;
     DripRate = dripRate;
     lastDrip = Environment.TickCount & Int32.MaxValue;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="parent">Parent bucket if this is a child bucket, or
 /// null if this is a root bucket</param>
 /// <param name="maxBurst">Maximum size of the bucket in bytes, or
 /// zero if this bucket has no maximum capacity</param>
 /// <param name="dripRate">Rate that the bucket fills, in bytes per
 /// second. If zero, the bucket always remains full</param>
 public TokenBucket(TokenBucket parent, int maxBurst, int dripRate)
 {
     this.parent = parent;
     MaxBurst    = maxBurst;
     DripRate    = dripRate;
     lastDrip    = Environment.TickCount & Int32.MaxValue;
 }
Exemplo n.º 3
0
        public LLUDPServer(LLUDP udp, IScene scene, IPAddress bindAddress, int port, IConfigSource configSource, IScheduler scheduler)
            : base(bindAddress, port)
        {
            m_udp = udp;
            Scene = scene;
            Scheduler = scheduler;

            IConfig throttleConfig = configSource.Configs["LLUDP"];
            m_throttleRates = new ThrottleRates(LLUDPServer.MTU, throttleConfig);

            m_resendTimer = new TimedEvent(100);
            m_ackTimer = new TimedEvent(500);
            m_pingTimer = new TimedEvent(5000);

            m_httpServer = Scene.Simian.GetAppModule<IHttpServer>();

            IConfig config = configSource.Configs["LLUDP"];
            if (config != null)
            {
                m_asyncPacketHandling = config.GetBoolean("AsyncPacketHandling", true);
                m_recvBufferSize = config.GetInt("SocketReceiveBufferSize", 0);
            }

            m_throttle = new TokenBucket(null, m_throttleRates.SceneTotalLimit, m_throttleRates.SceneTotal);

            PacketEvents = new PacketEventDictionary(Scheduler);

            Scene.OnPresenceRemove += PresenceRemoveHandler;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public WSAgent(WebSockets server, TokenBucket parentThrottle, ThrottleRates rates,
            UUID agentID, UUID sessionID, Socket socket, bool isChildAgent)
        {
            m_id = agentID;
            m_server = server;
            m_interestList = new InterestList(this, 200);

            IsChildPresence = isChildAgent;

            m_localID = m_server.Scene.CreateLocalID();

            //TextureEntry = new Primitive.TextureEntry(DEFAULT_AVATAR_TEXTURE);

            SessionID = sessionID;
            Socket = socket;

            // Create a token bucket throttle for this client that has the scene token bucket as a parent
            m_throttle = new TokenBucket(parentThrottle, rates.ClientTotalLimit, rates.ClientTotal);
            // Create an array of token buckets for this clients different throttle categories
            m_throttleCategories = new TokenBucket[THROTTLE_CATEGORY_COUNT];

            for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++)
            {
                ThrottleCategory type = (ThrottleCategory)i;

                // Initialize the message outboxes, where messages sit while they are waiting for tokens
                m_messageOutboxes[i] = new LocklessQueue<OutgoingMessage>();
                // Initialize the token buckets that control the throttling for each category
                m_throttleCategories[i] = new TokenBucket(m_throttle, rates.GetLimit(type), rates.GetRate(type));
            }

            // Initialize this to a sane value to prevent early disconnects
            TickLastMessageReceived = Environment.TickCount & Int32.MaxValue;
        }
Exemplo n.º 5
0
        public WebSocketServer(WebSockets server)
        {
            m_server = server;

            m_receiveBufferSize = MTU;
            m_readPool = new ObjectPool<SocketAsyncEventArgs>(0, CreateSocketArgs);

            // TODO: Support throttle config
            m_throttleRates = new ThrottleRates(MTU, null);
            m_throttle = new TokenBucket(null, m_throttleRates.SceneTotalLimit, m_throttleRates.SceneTotal);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="server">Reference to the UDP server this client is connected to</param>
        /// <param name="rates">Default throttling rates and maximum throttle limits</param>
        /// <param name="parentThrottle">Parent HTB (hierarchical token bucket)
        /// that the child throttles will be governed by</param>
        /// <param name="circuitCode">Circuit code for this connection</param>
        /// <param name="agentID">AgentID for the connected agent</param>
        /// <param name="sessionID">SessionID for the connected agent</param>
        /// <param name="secureSessionID">SecureSessionID for the connected agent</param>
        /// <param name="defaultRTO">Default retransmission timeout, in milliseconds</param>
        /// <param name="maxRTO">Maximum retransmission timeout, in milliseconds</param>
        /// <param name="remoteEndPoint">Remote endpoint for this connection</param>
        /// <param name="isChildAgent">True if this agent is currently simulated by
        /// another simulator, otherwise false</param>
        public LLAgent(LLUDPServer server, ThrottleRates rates, TokenBucket parentThrottle,
            uint circuitCode, UUID agentID, UUID sessionID, UUID secureSessionID, IPEndPoint remoteEndPoint,
            int defaultRTO, int maxRTO, bool isChildAgent)
        {
            m_id = agentID;
            m_udpServer = server;
            m_scene = m_udpServer.Scene;

            PacketArchive = new IncomingPacketHistoryCollection(200);
            NeedAcks = new UnackedPacketCollection();
            PendingAcks = new LocklessQueue<uint>();
            EventQueue = new LLEventQueue();

            m_nextOnQueueEmpty = 1;
            m_defaultRTO = 1000 * 3;
            m_maxRTO = 1000 * 60;

            m_packetOutboxes = new LocklessQueue<OutgoingPacket>[THROTTLE_CATEGORY_COUNT];
            m_nextPackets = new OutgoingPacket[THROTTLE_CATEGORY_COUNT];
            m_interestList = new InterestList(this, 200);

            IsChildPresence = isChildAgent;

            m_localID = m_scene.CreateLocalID();

            TextureEntry = new Primitive.TextureEntry(DEFAULT_AVATAR_TEXTURE);

            SessionID = sessionID;
            SecureSessionID = secureSessionID;
            RemoteEndPoint = remoteEndPoint;
            CircuitCode = circuitCode;

            if (defaultRTO != 0)
                m_defaultRTO = defaultRTO;
            if (maxRTO != 0)
                m_maxRTO = maxRTO;

            // Create a token bucket throttle for this client that has the scene token bucket as a parent
            m_throttle = new TokenBucket(parentThrottle, rates.ClientTotalLimit, rates.ClientTotal);
            // Create an array of token buckets for this clients different throttle categories
            m_throttleCategories = new TokenBucket[THROTTLE_CATEGORY_COUNT];

            for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++)
            {
                ThrottleCategory type = (ThrottleCategory)i;

                // Initialize the packet outboxes, where packets sit while they are waiting for tokens
                m_packetOutboxes[i] = new LocklessQueue<OutgoingPacket>();
                // Initialize the token buckets that control the throttling for each category
                m_throttleCategories[i] = new TokenBucket(m_throttle, rates.GetLimit(type), rates.GetRate(type));
            }

            // Default the retransmission timeout to three seconds
            RTO = m_defaultRTO;

            // Initialize this to a sane value to prevent early disconnects
            TickLastPacketReceived = Util.TickCount();

            IsConnected = true;
        }