diff options
author | Mike Rieker | 2011-02-20 15:57:57 +0000 |
---|---|---|
committer | Mike Rieker | 2011-02-20 15:57:57 +0000 |
commit | 86decb2aa8727a0c2ff51dd5c9a12d122585df3c (patch) | |
tree | 58bfd03332f03de30ee4412786939eaa8098d41e /OpenSim/Region/CoreModules | |
parent | Restore heartbeat thread (diff) | |
download | opensim-SC-86decb2aa8727a0c2ff51dd5c9a12d122585df3c.zip opensim-SC-86decb2aa8727a0c2ff51dd5c9a12d122585df3c.tar.gz opensim-SC-86decb2aa8727a0c2ff51dd5c9a12d122585df3c.tar.bz2 opensim-SC-86decb2aa8727a0c2ff51dd5c9a12d122585df3c.tar.xz |
throttle group notices to max of 4 threads at a time
...otherwise it can create hundreds of threads and hang
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs index dd9819a..a81ec7c 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs | |||
@@ -449,24 +449,37 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
449 | return resp; | 449 | return resp; |
450 | } | 450 | } |
451 | 451 | ||
452 | /// <summary> | 452 | private delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result); |
453 | /// delegate for sending a grid instant message asynchronously | ||
454 | /// </summary> | ||
455 | public delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result, UUID prevRegionID); | ||
456 | 453 | ||
457 | protected virtual void GridInstantMessageCompleted(IAsyncResult iar) | 454 | private class GIM { |
458 | { | 455 | public GridInstantMessage im; |
459 | GridInstantMessageDelegate icon = | 456 | public MessageResultNotification result; |
460 | (GridInstantMessageDelegate)iar.AsyncState; | 457 | }; |
461 | icon.EndInvoke(iar); | ||
462 | } | ||
463 | 458 | ||
459 | private Queue<GIM> pendingInstantMessages = new Queue<GIM>(); | ||
460 | private int numInstantMessageThreads = 0; | ||
464 | 461 | ||
465 | protected virtual void SendGridInstantMessageViaXMLRPC(GridInstantMessage im, MessageResultNotification result) | 462 | private void SendGridInstantMessageViaXMLRPC(GridInstantMessage im, MessageResultNotification result) |
466 | { | 463 | { |
467 | GridInstantMessageDelegate d = SendGridInstantMessageViaXMLRPCAsync; | 464 | lock (pendingInstantMessages) { |
465 | if (numInstantMessageThreads >= 4) { | ||
466 | GIM gim = new GIM(); | ||
467 | gim.im = im; | ||
468 | gim.result = result; | ||
469 | pendingInstantMessages.Enqueue(gim); | ||
470 | } else { | ||
471 | ++ numInstantMessageThreads; | ||
472 | m_log.DebugFormat("[SendGridInstantMessageViaXMLRPC]: ++numInstantMessageThreads={0}", numInstantMessageThreads); | ||
473 | GridInstantMessageDelegate d = SendGridInstantMessageViaXMLRPCAsyncMain; | ||
474 | d.BeginInvoke(im, result, GridInstantMessageCompleted, d); | ||
475 | } | ||
476 | } | ||
477 | } | ||
468 | 478 | ||
469 | d.BeginInvoke(im, result, UUID.Zero, GridInstantMessageCompleted, d); | 479 | private void GridInstantMessageCompleted(IAsyncResult iar) |
480 | { | ||
481 | GridInstantMessageDelegate d = (GridInstantMessageDelegate)iar.AsyncState; | ||
482 | d.EndInvoke(iar); | ||
470 | } | 483 | } |
471 | 484 | ||
472 | /// <summary> | 485 | /// <summary> |
@@ -481,8 +494,31 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
481 | /// Pass in 0 the first time this method is called. It will be called recursively with the last | 494 | /// Pass in 0 the first time this method is called. It will be called recursively with the last |
482 | /// regionhandle tried | 495 | /// regionhandle tried |
483 | /// </param> | 496 | /// </param> |
484 | protected virtual void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result, UUID prevRegionID) | 497 | private void SendGridInstantMessageViaXMLRPCAsyncMain(GridInstantMessage im, MessageResultNotification result) |
485 | { | 498 | { |
499 | GIM gim; | ||
500 | do { | ||
501 | try { | ||
502 | SendGridInstantMessageViaXMLRPCAsync(im, result, UUID.Zero); | ||
503 | } catch (Exception e) { | ||
504 | m_log.Error("[SendGridInstantMessageViaXMLRPC]: exception " + e.Message); | ||
505 | } | ||
506 | lock (pendingInstantMessages) { | ||
507 | if (pendingInstantMessages.Count > 0) { | ||
508 | gim = pendingInstantMessages.Dequeue(); | ||
509 | im = gim.im; | ||
510 | result = gim.result; | ||
511 | } else { | ||
512 | gim = null; | ||
513 | -- numInstantMessageThreads; | ||
514 | m_log.DebugFormat("[SendGridInstantMessageViaXMLRPC]: --numInstantMessageThreads={0}", numInstantMessageThreads); | ||
515 | } | ||
516 | } | ||
517 | } while (gim != null); | ||
518 | } | ||
519 | private void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result, UUID prevRegionID) | ||
520 | { | ||
521 | |||
486 | UUID toAgentID = new UUID(im.toAgentID); | 522 | UUID toAgentID = new UUID(im.toAgentID); |
487 | 523 | ||
488 | PresenceInfo upd = null; | 524 | PresenceInfo upd = null; |