aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2013-07-18 21:28:36 +0100
committerDiva Canto2013-07-21 08:56:48 -0700
commit63c42d66022ea7f1c2805b8f77980af5d4ba1fb4 (patch)
tree48bbe3212636cc81f525ba0d4c6ae56ad27b3551 /OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC-63c42d66022ea7f1c2805b8f77980af5d4ba1fb4.zip
opensim-SC-63c42d66022ea7f1c2805b8f77980af5d4ba1fb4.tar.gz
opensim-SC-63c42d66022ea7f1c2805b8f77980af5d4ba1fb4.tar.bz2
opensim-SC-63c42d66022ea7f1c2805b8f77980af5d4ba1fb4.tar.xz
Do some simple queue empty checks in the main outgoing udp loop instead of always performing these on a separate fired thread.
This appears to improve cpu usage since launching a new thread is more expensive than performing a small amount of inline logic. However, needs testing at scale.
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs69
1 files changed, 52 insertions, 17 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs
index 7749446..202cc62 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs
@@ -31,6 +31,7 @@ using System.Net;
31using System.Threading; 31using System.Threading;
32using log4net; 32using log4net;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Framework.Monitoring;
34using OpenMetaverse; 35using OpenMetaverse;
35using OpenMetaverse.Packets; 36using OpenMetaverse.Packets;
36 37
@@ -81,6 +82,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
81 /// hooked to put more data on the empty queue</summary> 82 /// hooked to put more data on the empty queue</summary>
82 public event QueueEmpty OnQueueEmpty; 83 public event QueueEmpty OnQueueEmpty;
83 84
85 public event Func<ThrottleOutPacketTypeFlags, bool> HasUpdates;
86
84 /// <summary>AgentID for this client</summary> 87 /// <summary>AgentID for this client</summary>
85 public readonly UUID AgentID; 88 public readonly UUID AgentID;
86 /// <summary>The remote address of the connected client</summary> 89 /// <summary>The remote address of the connected client</summary>
@@ -613,15 +616,38 @@ namespace OpenSim.Region.ClientStack.LindenUDP
613 /// <param name="categories">Throttle categories to fire the callback for</param> 616 /// <param name="categories">Throttle categories to fire the callback for</param>
614 private void BeginFireQueueEmpty(ThrottleOutPacketTypeFlags categories) 617 private void BeginFireQueueEmpty(ThrottleOutPacketTypeFlags categories)
615 { 618 {
616 if (m_nextOnQueueEmpty != 0 && (Environment.TickCount & Int32.MaxValue) >= m_nextOnQueueEmpty) 619// if (m_nextOnQueueEmpty != 0 && (Environment.TickCount & Int32.MaxValue) >= m_nextOnQueueEmpty)
620 if (!m_isQueueEmptyRunning && (Environment.TickCount & Int32.MaxValue) >= m_nextOnQueueEmpty)
617 { 621 {
622 m_isQueueEmptyRunning = true;
623
624 int start = Environment.TickCount & Int32.MaxValue;
625 const int MIN_CALLBACK_MS = 30;
626
627 m_nextOnQueueEmpty = start + MIN_CALLBACK_MS;
628 if (m_nextOnQueueEmpty == 0)
629 m_nextOnQueueEmpty = 1;
630
618 // Use a value of 0 to signal that FireQueueEmpty is running 631 // Use a value of 0 to signal that FireQueueEmpty is running
619 m_nextOnQueueEmpty = 0; 632// m_nextOnQueueEmpty = 0;
620 // Asynchronously run the callback 633
621 Util.FireAndForget(FireQueueEmpty, categories); 634 m_categories = categories;
635
636 if (HasUpdates(m_categories))
637 {
638 // Asynchronously run the callback
639 Util.FireAndForget(FireQueueEmpty, categories);
640 }
641 else
642 {
643 m_isQueueEmptyRunning = false;
644 }
622 } 645 }
623 } 646 }
624 647
648 private bool m_isQueueEmptyRunning;
649 private ThrottleOutPacketTypeFlags m_categories = 0;
650
625 /// <summary> 651 /// <summary>
626 /// Fires the OnQueueEmpty callback and sets the minimum time that it 652 /// Fires the OnQueueEmpty callback and sets the minimum time that it
627 /// can be called again 653 /// can be called again
@@ -631,22 +657,31 @@ namespace OpenSim.Region.ClientStack.LindenUDP
631 /// signature</param> 657 /// signature</param>
632 private void FireQueueEmpty(object o) 658 private void FireQueueEmpty(object o)
633 { 659 {
634 const int MIN_CALLBACK_MS = 30; 660// int start = Environment.TickCount & Int32.MaxValue;
661// const int MIN_CALLBACK_MS = 30;
635 662
636 ThrottleOutPacketTypeFlags categories = (ThrottleOutPacketTypeFlags)o; 663// if (m_udpServer.IsRunningOutbound)
637 QueueEmpty callback = OnQueueEmpty; 664// {
638 665 ThrottleOutPacketTypeFlags categories = (ThrottleOutPacketTypeFlags)o;
639 int start = Environment.TickCount & Int32.MaxValue; 666 QueueEmpty callback = OnQueueEmpty;
640 667
641 if (callback != null) 668 if (callback != null)
642 { 669 {
643 try { callback(categories); } 670// if (m_udpServer.IsRunningOutbound)
644 catch (Exception e) { m_log.Error("[LLUDPCLIENT]: OnQueueEmpty(" + categories + ") threw an exception: " + e.Message, e); } 671// {
645 } 672 try { callback(categories); }
673 catch (Exception e) { m_log.Error("[LLUDPCLIENT]: OnQueueEmpty(" + categories + ") threw an exception: " + e.Message, e); }
674// }
675 }
676// }
677
678// m_nextOnQueueEmpty = start + MIN_CALLBACK_MS;
679// if (m_nextOnQueueEmpty == 0)
680// m_nextOnQueueEmpty = 1;
681
682// }
646 683
647 m_nextOnQueueEmpty = start + MIN_CALLBACK_MS; 684 m_isQueueEmptyRunning = false;
648 if (m_nextOnQueueEmpty == 0)
649 m_nextOnQueueEmpty = 1;
650 } 685 }
651 686
652 /// <summary> 687 /// <summary>