diff options
author | Diva Canto | 2013-07-04 14:51:18 -0700 |
---|---|---|
committer | Diva Canto | 2013-07-04 14:51:18 -0700 |
commit | 8265a88c4a4b1c18f1bc0accfde250fe47b08c50 (patch) | |
tree | f2ca5aedd90f0bb304235437d08ff4dc6b2293bd /OpenSim/Region/CoreModules/Framework/GridServiceThrottle | |
parent | Guard against completely unknown user UUIDs. (diff) | |
download | opensim-SC-8265a88c4a4b1c18f1bc0accfde250fe47b08c50.zip opensim-SC-8265a88c4a4b1c18f1bc0accfde250fe47b08c50.tar.gz opensim-SC-8265a88c4a4b1c18f1bc0accfde250fe47b08c50.tar.bz2 opensim-SC-8265a88c4a4b1c18f1bc0accfde250fe47b08c50.tar.xz |
Throttle the viewer's requests for region handles. Apparently Kokua is requesting this for all landmarks in inventory. Not sure why. But this seems to be the root cause of the login freeze mentioned before. This commit adds a blocking queue / process thread pattern.
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/GridServiceThrottle')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs b/OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs new file mode 100644 index 0000000..5511fea --- /dev/null +++ b/OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs | |||
@@ -0,0 +1,161 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Threading; | ||
32 | using log4net; | ||
33 | using Mono.Addins; | ||
34 | using Nini.Config; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Framework.Monitoring; | ||
39 | using OpenSim.Region.Framework.Scenes; | ||
40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
41 | |||
42 | namespace OpenSim.Region.CoreModules.Framework | ||
43 | { | ||
44 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GridServiceThrottleModule")] | ||
45 | public class GridServiceThrottleModule : ISharedRegionModule | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger( | ||
48 | MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private readonly List<Scene> m_scenes = new List<Scene>(); | ||
51 | |||
52 | private OpenSim.Framework.BlockingQueue<GridRegionRequest> m_RequestQueue = new OpenSim.Framework.BlockingQueue<GridRegionRequest>(); | ||
53 | |||
54 | public void Initialise(IConfigSource config) | ||
55 | { | ||
56 | Watchdog.StartThread( | ||
57 | ProcessQueue, | ||
58 | "GridServiceRequestThread", | ||
59 | ThreadPriority.BelowNormal, | ||
60 | true, | ||
61 | true); | ||
62 | } | ||
63 | |||
64 | public void AddRegion(Scene scene) | ||
65 | { | ||
66 | lock (m_scenes) | ||
67 | { | ||
68 | m_scenes.Add(scene); | ||
69 | scene.EventManager.OnNewClient += OnNewClient; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | public void RegionLoaded(Scene scene) | ||
74 | { | ||
75 | } | ||
76 | |||
77 | public void RemoveRegion(Scene scene) | ||
78 | { | ||
79 | lock (m_scenes) | ||
80 | { | ||
81 | m_scenes.Remove(scene); | ||
82 | scene.EventManager.OnNewClient -= OnNewClient; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | void OnNewClient(IClientAPI client) | ||
87 | { | ||
88 | client.OnRegionHandleRequest += OnRegionHandleRequest; | ||
89 | } | ||
90 | |||
91 | public void PostInitialise() | ||
92 | { | ||
93 | } | ||
94 | |||
95 | public void Close() | ||
96 | { | ||
97 | } | ||
98 | |||
99 | public string Name | ||
100 | { | ||
101 | get { return "GridServiceThrottleModule"; } | ||
102 | } | ||
103 | |||
104 | public Type ReplaceableInterface | ||
105 | { | ||
106 | get { return null; } | ||
107 | } | ||
108 | |||
109 | public void OnRegionHandleRequest(IClientAPI client, UUID regionID) | ||
110 | { | ||
111 | m_log.DebugFormat("[GRIDSERVICE THROTTLE]: RegionHandleRequest {0}", regionID); | ||
112 | ulong handle = 0; | ||
113 | if (IsLocalRegionHandle(regionID, out handle)) | ||
114 | { | ||
115 | client.SendRegionHandle(regionID, handle); | ||
116 | return; | ||
117 | } | ||
118 | |||
119 | GridRegionRequest request = new GridRegionRequest(client, regionID); | ||
120 | m_RequestQueue.Enqueue(request); | ||
121 | |||
122 | } | ||
123 | |||
124 | private bool IsLocalRegionHandle(UUID regionID, out ulong regionHandle) | ||
125 | { | ||
126 | regionHandle = 0; | ||
127 | foreach (Scene s in m_scenes) | ||
128 | if (s.RegionInfo.RegionID == regionID) | ||
129 | { | ||
130 | regionHandle = s.RegionInfo.RegionHandle; | ||
131 | return true; | ||
132 | } | ||
133 | return false; | ||
134 | } | ||
135 | |||
136 | private void ProcessQueue() | ||
137 | { | ||
138 | while (true) | ||
139 | { | ||
140 | GridRegionRequest request = m_RequestQueue.Dequeue(); | ||
141 | GridRegion r = m_scenes[0].GridService.GetRegionByUUID(UUID.Zero, request.regionID); | ||
142 | |||
143 | if (r != null && r.RegionHandle != 0) | ||
144 | request.client.SendRegionHandle(request.regionID, r.RegionHandle); | ||
145 | |||
146 | } | ||
147 | } | ||
148 | } | ||
149 | |||
150 | class GridRegionRequest | ||
151 | { | ||
152 | public IClientAPI client; | ||
153 | public UUID regionID; | ||
154 | |||
155 | public GridRegionRequest(IClientAPI c, UUID r) | ||
156 | { | ||
157 | client = c; | ||
158 | regionID = r; | ||
159 | } | ||
160 | } | ||
161 | } | ||