aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Framework/ServiceThrottle
diff options
context:
space:
mode:
authorUbitUmarov2016-11-22 22:24:54 +0000
committerUbitUmarov2016-11-22 22:24:54 +0000
commitf4745e5a354871c5b248d10bb57f40cae5cc788c (patch)
tree5b13f965a77ba6e0fbf6a3c3b7a62389bbde607d /OpenSim/Region/CoreModules/Framework/ServiceThrottle
parentMinor fix to region default landing point sanity check (diff)
downloadopensim-SC_OLD-f4745e5a354871c5b248d10bb57f40cae5cc788c.zip
opensim-SC_OLD-f4745e5a354871c5b248d10bb57f40cae5cc788c.tar.gz
opensim-SC_OLD-f4745e5a354871c5b248d10bb57f40cae5cc788c.tar.bz2
opensim-SC_OLD-f4745e5a354871c5b248d10bb57f40cae5cc788c.tar.xz
full change ServiceThrottleModule. Let it still service RegionHandleRequest and UUIDNameRequest but this wrong since they are diferent services. Keeping gambling about not having 2 much overlaps of the 2 kind of requests. Remove double thottling of RegionHandleRequest
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/ServiceThrottle')
-rw-r--r--OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs140
1 files changed, 15 insertions, 125 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs b/OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs
index 3abacbd..36fb57a 100644
--- a/OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs
@@ -48,31 +48,16 @@ namespace OpenSim.Region.CoreModules.Framework
48 MethodBase.GetCurrentMethod().DeclaringType); 48 MethodBase.GetCurrentMethod().DeclaringType);
49 49
50 private readonly List<Scene> m_scenes = new List<Scene>(); 50 private readonly List<Scene> m_scenes = new List<Scene>();
51 private System.Timers.Timer m_timer = new System.Timers.Timer(); 51 private JobEngine m_processorJobEngine;
52 52
53 private Queue<Action> m_RequestQueue = new Queue<Action>();
54 private Dictionary<string, List<string>> m_Pending = new Dictionary<string, List<string>>();
55 private int m_Interval;
56
57 #region ISharedRegionModule 53 #region ISharedRegionModule
58 54
59 public void Initialise(IConfigSource config) 55 public void Initialise(IConfigSource config)
60 { 56 {
61 m_Interval = Util.GetConfigVarFromSections<int>(config, "Interval", new string[] { "ServiceThrottle" }, 5000); 57 m_processorJobEngine = new JobEngine(
62 58 "ServiceThrottle","ServiceThrottle");
63 m_timer = new System.Timers.Timer(); 59 m_processorJobEngine.RequestProcessTimeoutOnStop = 31000; // many webrequests have 30s expire
64 m_timer.AutoReset = false; 60 m_processorJobEngine.Start();
65 m_timer.Enabled = true;
66 m_timer.Interval = 15000; // 15 secs at first
67 m_timer.Elapsed += ProcessQueue;
68 m_timer.Start();
69
70 //WorkManager.StartThread(
71 // ProcessQueue,
72 // "GridServiceRequestThread",
73 // ThreadPriority.BelowNormal,
74 // true,
75 // false);
76 } 61 }
77 62
78 public void AddRegion(Scene scene) 63 public void AddRegion(Scene scene)
@@ -82,7 +67,6 @@ namespace OpenSim.Region.CoreModules.Framework
82 m_scenes.Add(scene); 67 m_scenes.Add(scene);
83 scene.RegisterModuleInterface<IServiceThrottleModule>(this); 68 scene.RegisterModuleInterface<IServiceThrottleModule>(this);
84 scene.EventManager.OnNewClient += OnNewClient; 69 scene.EventManager.OnNewClient += OnNewClient;
85 scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
86 } 70 }
87 } 71 }
88 72
@@ -105,6 +89,7 @@ namespace OpenSim.Region.CoreModules.Framework
105 89
106 public void Close() 90 public void Close()
107 { 91 {
92 m_processorJobEngine.Stop();
108 } 93 }
109 94
110 public string Name 95 public string Name
@@ -126,38 +111,24 @@ namespace OpenSim.Region.CoreModules.Framework
126 client.OnRegionHandleRequest += OnRegionHandleRequest; 111 client.OnRegionHandleRequest += OnRegionHandleRequest;
127 } 112 }
128 113
129 void OnMakeRootAgent(ScenePresence obj)
130 {
131 lock (m_timer)
132 {
133 if (!m_timer.Enabled)
134 {
135 m_timer.Interval = m_Interval;
136 m_timer.Enabled = true;
137 m_timer.Start();
138 }
139 }
140 }
141
142 public void OnRegionHandleRequest(IClientAPI client, UUID regionID) 114 public void OnRegionHandleRequest(IClientAPI client, UUID regionID)
143 { 115 {
144 //m_log.DebugFormat("[SERVICE THROTTLE]: RegionHandleRequest {0}", regionID); 116 //m_log.DebugFormat("[SERVICE THROTTLE]: RegionHandleRequest {0}", regionID);
145 ulong handle = 0;
146 if (IsLocalRegionHandle(regionID, out handle))
147 {
148 client.SendRegionHandle(regionID, handle);
149 return;
150 }
151
152 Action action = delegate 117 Action action = delegate
153 { 118 {
119 if(!client.IsActive)
120 return;
121
154 GridRegion r = m_scenes[0].GridService.GetRegionByUUID(UUID.Zero, regionID); 122 GridRegion r = m_scenes[0].GridService.GetRegionByUUID(UUID.Zero, regionID);
155 123
124 if(!client.IsActive)
125 return;
126
156 if (r != null && r.RegionHandle != 0) 127 if (r != null && r.RegionHandle != 0)
157 client.SendRegionHandle(regionID, r.RegionHandle); 128 client.SendRegionHandle(regionID, r.RegionHandle);
158 }; 129 };
159 130
160 Enqueue("region", regionID.ToString(), action); 131 m_processorJobEngine.QueueJob("regionHandle", action, regionID.ToString());
161 } 132 }
162 133
163 #endregion Events 134 #endregion Events
@@ -166,91 +137,10 @@ namespace OpenSim.Region.CoreModules.Framework
166 137
167 public void Enqueue(string category, string itemid, Action continuation) 138 public void Enqueue(string category, string itemid, Action continuation)
168 { 139 {
169 lock (m_RequestQueue) 140 m_processorJobEngine.QueueJob(category, continuation, itemid);
170 {
171 if (m_Pending.ContainsKey(category))
172 {
173 if (m_Pending[category].Contains(itemid))
174 // Don't enqueue, it's already pending
175 return;
176 }
177 else
178 m_Pending.Add(category, new List<string>());
179
180 m_Pending[category].Add(itemid);
181
182 m_RequestQueue.Enqueue(delegate
183 {
184 lock (m_RequestQueue)
185 m_Pending[category].Remove(itemid);
186
187 continuation();
188 });
189 }
190 } 141 }
191 142
192 #endregion IServiceThrottleModule 143 #endregion IServiceThrottleModule
193
194 #region Process Continuation Queue
195
196 private void ProcessQueue(object sender, System.Timers.ElapsedEventArgs e)
197 {
198 //m_log.DebugFormat("[YYY]: Process queue with {0} continuations", m_RequestQueue.Count);
199
200 while (m_RequestQueue.Count > 0)
201 {
202 Action continuation = null;
203 lock (m_RequestQueue)
204 continuation = m_RequestQueue.Dequeue();
205
206 if (continuation != null)
207 continuation();
208 }
209
210 if (AreThereRootAgents())
211 {
212 lock (m_timer)
213 {
214 m_timer.Interval = 1000; // 1 sec
215 m_timer.Enabled = true;
216 m_timer.Start();
217 }
218 }
219 else
220 lock (m_timer)
221 m_timer.Enabled = false;
222
223 }
224
225 #endregion Process Continuation Queue
226
227 #region Misc
228
229 private bool IsLocalRegionHandle(UUID regionID, out ulong regionHandle)
230 {
231 regionHandle = 0;
232 foreach (Scene s in m_scenes)
233 if (s.RegionInfo.RegionID == regionID)
234 {
235 regionHandle = s.RegionInfo.RegionHandle;
236 return true;
237 }
238 return false;
239 }
240
241 private bool AreThereRootAgents()
242 {
243 foreach (Scene s in m_scenes)
244 {
245 foreach (ScenePresence sp in s.GetScenePresences())
246 if (!sp.IsChildAgent)
247 return true;
248 }
249
250 return false;
251 }
252
253 #endregion Misc
254 } 144 }
255 145
256} 146}