diff options
author | Justin Clark-Casey (justincc) | 2014-08-13 22:38:27 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2014-08-13 22:38:27 +0100 |
commit | 21176a3a901dd2190a1847acf576b938c0885e23 (patch) | |
tree | de76b08895632480f439bc026127126523c8ca93 /OpenSim/Tools/pCampBot/Bot.cs | |
parent | Add 'server' stats information to pCampbot, as used elsewhere in OpenSimulator (diff) | |
download | opensim-SC-21176a3a901dd2190a1847acf576b938c0885e23.zip opensim-SC-21176a3a901dd2190a1847acf576b938c0885e23.tar.gz opensim-SC-21176a3a901dd2190a1847acf576b938c0885e23.tar.bz2 opensim-SC-21176a3a901dd2190a1847acf576b938c0885e23.tar.xz |
Terminate 'nothing' behaviour (and potentially others) by signalling using an event rather than polling connection state every 100ms
This kind of polling is very expensive with many bots/polling threads and appears to be the primary cause of bot falloff from the client end at higher loads.
Where inbound packet threads can't run in time due to contention and simulator disconnect timeout occurs.
Diffstat (limited to 'OpenSim/Tools/pCampBot/Bot.cs')
-rw-r--r-- | OpenSim/Tools/pCampBot/Bot.cs | 58 |
1 files changed, 25 insertions, 33 deletions
diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs index bd5eb81..fd9ae3f 100644 --- a/OpenSim/Tools/pCampBot/Bot.cs +++ b/OpenSim/Tools/pCampBot/Bot.cs | |||
@@ -192,15 +192,15 @@ namespace pCampBot | |||
192 | 192 | ||
193 | public bool AddBehaviour(IBehaviour behaviour) | 193 | public bool AddBehaviour(IBehaviour behaviour) |
194 | { | 194 | { |
195 | lock (Behaviours) | 195 | Dictionary<string, IBehaviour> updatedBehaviours = new Dictionary<string, IBehaviour>(Behaviours); |
196 | { | ||
197 | if (!Behaviours.ContainsKey(behaviour.AbbreviatedName)) | ||
198 | { | ||
199 | behaviour.Initialize(this); | ||
200 | Behaviours.Add(behaviour.AbbreviatedName, behaviour); | ||
201 | 196 | ||
202 | return true; | 197 | if (!updatedBehaviours.ContainsKey(behaviour.AbbreviatedName)) |
203 | } | 198 | { |
199 | behaviour.Initialize(this); | ||
200 | updatedBehaviours.Add(behaviour.AbbreviatedName, behaviour); | ||
201 | Behaviours = updatedBehaviours; | ||
202 | |||
203 | return true; | ||
204 | } | 204 | } |
205 | 205 | ||
206 | return false; | 206 | return false; |
@@ -208,18 +208,17 @@ namespace pCampBot | |||
208 | 208 | ||
209 | public bool RemoveBehaviour(string abbreviatedName) | 209 | public bool RemoveBehaviour(string abbreviatedName) |
210 | { | 210 | { |
211 | lock (Behaviours) | 211 | Dictionary<string, IBehaviour> updatedBehaviours = new Dictionary<string, IBehaviour>(Behaviours); |
212 | { | 212 | IBehaviour behaviour; |
213 | IBehaviour behaviour; | ||
214 | 213 | ||
215 | if (!Behaviours.TryGetValue(abbreviatedName, out behaviour)) | 214 | if (!updatedBehaviours.TryGetValue(abbreviatedName, out behaviour)) |
216 | return false; | 215 | return false; |
217 | 216 | ||
218 | behaviour.Close(); | 217 | behaviour.Close(); |
219 | Behaviours.Remove(abbreviatedName); | 218 | updatedBehaviours.Remove(abbreviatedName); |
219 | Behaviours = updatedBehaviours; | ||
220 | 220 | ||
221 | return true; | 221 | return true; |
222 | } | ||
223 | } | 222 | } |
224 | 223 | ||
225 | private void CreateLibOmvClient() | 224 | private void CreateLibOmvClient() |
@@ -279,24 +278,17 @@ namespace pCampBot | |||
279 | { | 278 | { |
280 | while (ConnectionState == ConnectionState.Connected) | 279 | while (ConnectionState == ConnectionState.Connected) |
281 | { | 280 | { |
282 | lock (Behaviours) | 281 | foreach (IBehaviour behaviour in Behaviours.Values) |
283 | { | 282 | { |
284 | foreach (IBehaviour behaviour in Behaviours.Values) | ||
285 | { | ||
286 | // Thread.Sleep(Random.Next(3000, 10000)); | 283 | // Thread.Sleep(Random.Next(3000, 10000)); |
287 | 284 | ||
288 | // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType()); | 285 | // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType()); |
289 | behaviour.Action(); | 286 | behaviour.Action(); |
290 | } | ||
291 | } | 287 | } |
292 | |||
293 | // XXX: This is a really shitty way of yielding so that behaviours can be added/removed | ||
294 | Thread.Sleep(100); | ||
295 | } | 288 | } |
296 | 289 | ||
297 | lock (Behaviours) | 290 | foreach (IBehaviour b in Behaviours.Values) |
298 | foreach (IBehaviour b in Behaviours.Values) | 291 | b.Close(); |
299 | b.Close(); | ||
300 | } | 292 | } |
301 | 293 | ||
302 | /// <summary> | 294 | /// <summary> |
@@ -305,9 +297,9 @@ namespace pCampBot | |||
305 | public void Disconnect() | 297 | public void Disconnect() |
306 | { | 298 | { |
307 | ConnectionState = ConnectionState.Disconnecting; | 299 | ConnectionState = ConnectionState.Disconnecting; |
308 | 300 | ||
309 | // if (m_actionThread != null) | 301 | foreach (IBehaviour behaviour in Behaviours.Values) |
310 | // m_actionThread.Abort(); | 302 | behaviour.Interrupt(); |
311 | 303 | ||
312 | Client.Network.Logout(); | 304 | Client.Network.Logout(); |
313 | } | 305 | } |