aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework
diff options
context:
space:
mode:
authorThomas Grimshaw2010-04-05 22:11:05 +0200
committerThomas Grimshaw2010-04-05 22:11:05 +0200
commit7a3bb266ebc057a1af589fc642bfeca08de72c98 (patch)
tree61ba6bf18dea258f8e11b4ce3422fe42561a2b32 /OpenSim/Region/Framework
parentAdd a much cheaper agent count retrieval method. This is obsoleted by 0.7 so... (diff)
downloadopensim-SC_OLD-7a3bb266ebc057a1af589fc642bfeca08de72c98.zip
opensim-SC_OLD-7a3bb266ebc057a1af589fc642bfeca08de72c98.tar.gz
opensim-SC_OLD-7a3bb266ebc057a1af589fc642bfeca08de72c98.tar.bz2
opensim-SC_OLD-7a3bb266ebc057a1af589fc642bfeca08de72c98.tar.xz
This commit adds some randomness to object persistence. It's a Work In Progress, I am working on improving this to a tiered approach.
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs46
1 files changed, 42 insertions, 4 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index 5443c28..9a205e0 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -104,8 +104,12 @@ namespace OpenSim.Region.Framework.Scenes
104 /// since the group's last persistent backup 104 /// since the group's last persistent backup
105 /// </summary> 105 /// </summary>
106 private bool m_hasGroupChanged = false; 106 private bool m_hasGroupChanged = false;
107 private long timeFirstChanged; 107 private long timeFirstChanged = 0;
108 private long timeLastChanged; 108 private long timeLastChanged = 0;
109 long m_maxPersistTime = 0;
110 long m_minPersistTime = 0;
111 Random m_rand;
112
109 private System.Threading.ReaderWriterLockSlim m_partsLock = new System.Threading.ReaderWriterLockSlim(); 113 private System.Threading.ReaderWriterLockSlim m_partsLock = new System.Threading.ReaderWriterLockSlim();
110 114
111 public void lockPartsForRead(bool locked) 115 public void lockPartsForRead(bool locked)
@@ -182,6 +186,28 @@ namespace OpenSim.Region.Framework.Scenes
182 timeLastChanged = DateTime.Now.Ticks; 186 timeLastChanged = DateTime.Now.Ticks;
183 if (!m_hasGroupChanged) 187 if (!m_hasGroupChanged)
184 timeFirstChanged = DateTime.Now.Ticks; 188 timeFirstChanged = DateTime.Now.Ticks;
189 if (m_rand == null)
190 {
191 byte[] val = new byte[16];
192 m_rootPart.UUID.ToBytes(val, 0);
193 m_rand = new Random(BitConverter.ToInt32(val, 0));
194 }
195 if (Scene.GetRootAgentCount() == 0)
196 {
197 //If the region is empty, this change has been made by an automated process
198 //and thus we delay the persist time by a random amount between 1.5 and 2.5.
199
200 float factor = 1.5f + (float)(m_rand.NextDouble());
201 m_maxPersistTime = (long)((float)Scene.m_persistAfter * factor);
202 m_minPersistTime = (long)((float)Scene.m_dontPersistBefore * factor);
203 }
204 else
205 {
206 //If the region is not empty, we want to obey the minimum and maximum persist times
207 //but add a random factor so we stagger the object persistance a little
208 m_maxPersistTime = (long)((float)Scene.m_persistAfter * (1.0d - (m_rand.NextDouble() / 5.0d))); //Multiply by 1.0-1.5
209 m_minPersistTime = (long)((float)Scene.m_dontPersistBefore * (1.0d + (m_rand.NextDouble() / 2.0d))); //Multiply by 0.8-1.0
210 }
185 } 211 }
186 m_hasGroupChanged = value; 212 m_hasGroupChanged = value;
187 } 213 }
@@ -197,8 +223,19 @@ namespace OpenSim.Region.Framework.Scenes
197 return false; 223 return false;
198 if (m_scene.ShuttingDown) 224 if (m_scene.ShuttingDown)
199 return true; 225 return true;
226
227 if (m_minPersistTime == 0 || m_maxPersistTime == 0)
228 {
229 m_maxPersistTime = m_scene.m_persistAfter;
230 m_minPersistTime = m_scene.m_dontPersistBefore;
231 }
232
200 long currentTime = DateTime.Now.Ticks; 233 long currentTime = DateTime.Now.Ticks;
201 if (currentTime - timeLastChanged > m_scene.m_dontPersistBefore || currentTime - timeFirstChanged > m_scene.m_persistAfter) 234
235 if (timeLastChanged == 0) timeLastChanged = currentTime;
236 if (timeFirstChanged == 0) timeFirstChanged = currentTime;
237
238 if (currentTime - timeLastChanged > m_minPersistTime || currentTime - timeFirstChanged > m_maxPersistTime)
202 return true; 239 return true;
203 return false; 240 return false;
204 } 241 }
@@ -529,6 +566,7 @@ namespace OpenSim.Region.Framework.Scenes
529 /// </summary> 566 /// </summary>
530 public SceneObjectGroup() 567 public SceneObjectGroup()
531 { 568 {
569
532 } 570 }
533 571
534 /// <summary> 572 /// <summary>
@@ -545,7 +583,7 @@ namespace OpenSim.Region.Framework.Scenes
545 /// Constructor. This object is added to the scene later via AttachToScene() 583 /// Constructor. This object is added to the scene later via AttachToScene()
546 /// </summary> 584 /// </summary>
547 public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape) 585 public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape)
548 { 586 {
549 SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero)); 587 SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero));
550 } 588 }
551 589