public bool EnqueueOutgoing(OutgoingMessage message) { int category = (int)message.Category; if (category >= 0 && category < m_messageOutboxes.Length) { LocklessQueue <OutgoingMessage> queue = m_messageOutboxes[category]; TokenBucket bucket = m_throttleCategories[category]; if (bucket.RemoveTokens(message.Data.Length)) { // Enough tokens were removed from the bucket, the message will not be queued return(false); } else { // Not enough tokens in the bucket, queue this message queue.Enqueue(message); return(true); } } else { // We don't have a token bucket for this category, so it will not be queued return(false); } }
/// <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 = Util.TickCount(); }
public void Clear() { m_packets.Clear(); m_pendingAdds = null; m_pendingAcknowledgements = null; m_pendingRemoves = null; }
public bool EnqueueOutgoing(OutgoingPacket packet) { int category = (int)packet.Category; if (category >= 0 && category < m_packetOutboxes.Length) { LocklessQueue <OutgoingPacket> queue = m_packetOutboxes[category]; TokenBucket bucket = m_throttleCategories[category]; if (bucket.RemoveTokens(packet.Buffer.DataLength)) { // Enough tokens were removed from the bucket, the packet will not be queued return(false); } else { // Not enough tokens in the bucket, queue this packet queue.Enqueue(packet); return(true); } } else { // We don't have a token bucket for this category, so it will not be queued return(false); } }
/// <summary> /// Shuts down this client connection /// </summary> public void Shutdown() { m_log.Info("Shutting down WS agent " + this.Name); IsConnected = false; for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++) { m_messageOutboxes[i] = new LocklessQueue <OutgoingMessage>(); m_nextMessages[i] = null; } m_server.Scene.EntityRemove(this, this); }
/// <summary> /// Shuts down this client connection /// </summary> public void Shutdown() { m_log.Info("Shutting down agent " + this.Name); IsConnected = false; for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++) { m_packetOutboxes[i] = new LocklessQueue <OutgoingPacket>(); m_nextPackets[i] = null; } EventQueue.Dispose(); m_scene.EntityRemove(this, this); }
public ContextTimeoutManager(MonitorType pMonitorType) { _contexts = new LocklessQueue<HttpClientContext>(); _monitoringType = pMonitorType; switch (pMonitorType) { case MonitorType.Thread: _internalThread = new Thread(ThreadRunProcess); _internalThread.Priority = ThreadPriority.Lowest; _internalThread.IsBackground = true; _internalThread.CurrentCulture = new CultureInfo("en-US", false); _internalThread.Name = "HttpServer Internal Zombie Timeout Checker"; _internalThread.Start(); break; case MonitorType.Timer: _internalTimer = new Timer(TimerCallbackCheck, null, _monitorMS, _monitorMS); break; } }
/// <summary> /// Shuts down this client connection /// </summary> public void Shutdown() { m_log.Info("Shutting down WS agent " + this.Name); IsConnected = false; for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++) { m_messageOutboxes[i] = new LocklessQueue<OutgoingMessage>(); m_nextMessages[i] = null; } m_server.Scene.EntityRemove(this, this); }
/// <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; }
/// <summary> /// Shuts down this client connection /// </summary> public void Shutdown() { m_log.Info("Shutting down agent " + this.Name); IsConnected = false; for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++) { m_packetOutboxes[i] = new LocklessQueue<OutgoingPacket>(); m_nextPackets[i] = null; } EventQueue.Dispose(); m_scene.EntityRemove(this, this); }
/// <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; }
/// <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; }