aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs148
1 files changed, 23 insertions, 125 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs b/OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs
index 3abacbd..2c74c0e 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
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 52
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,32 @@ 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 {
154 GridRegion r = m_scenes[0].GridService.GetRegionByUUID(UUID.Zero, regionID); 119 if(!client.IsActive)
120 return;
121
122 if(m_scenes.Count == 0)
123 return;
124
125 Scene baseScene = m_scenes[0];
126
127 if(baseScene == null || baseScene.ShuttingDown)
128 return;
129
130 GridRegion r = baseScene.GridService.GetRegionByUUID(UUID.Zero, regionID);
131
132 if(!client.IsActive)
133 return;
155 134
156 if (r != null && r.RegionHandle != 0) 135 if (r != null && r.RegionHandle != 0)
157 client.SendRegionHandle(regionID, r.RegionHandle); 136 client.SendRegionHandle(regionID, r.RegionHandle);
158 }; 137 };
159 138
160 Enqueue("region", regionID.ToString(), action); 139 m_processorJobEngine.QueueJob("regionHandle", action, regionID.ToString());
161 } 140 }
162 141
163 #endregion Events 142 #endregion Events
@@ -166,91 +145,10 @@ namespace OpenSim.Region.CoreModules.Framework
166 145
167 public void Enqueue(string category, string itemid, Action continuation) 146 public void Enqueue(string category, string itemid, Action continuation)
168 { 147 {
169 lock (m_RequestQueue) 148 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 } 149 }
191 150
192 #endregion IServiceThrottleModule 151 #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 } 152 }
255 153
256} 154}