From 53be4774b32f6736373c1364c3bd659c977fbb4e Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Sat, 25 Aug 2007 15:31:47 +0000 Subject: Scripts no longer crash sim after 5 minutes (override InitializeLifetimeService). Loading/Unloading of scripts are now handled in separate thread so server is no delayed because of this. Each script is loaded into a single AppDomain (temporary test for script unload, eats ~15KB more memory for each script). Unload of scripts has been verified to free up memory. --- OpenSim/Region/ScriptEngine/Common/Executor.cs | 43 ++++++++++++++------------ 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Common') diff --git a/OpenSim/Region/ScriptEngine/Common/Executor.cs b/OpenSim/Region/ScriptEngine/Common/Executor.cs index 148ae0f..cadd55c 100644 --- a/OpenSim/Region/ScriptEngine/Common/Executor.cs +++ b/OpenSim/Region/ScriptEngine/Common/Executor.cs @@ -2,34 +2,40 @@ using System; using System.Collections.Generic; using System.Text; using System.Reflection; +using System.Runtime.Remoting.Lifetime; namespace OpenSim.Region.ScriptEngine.Common { public class Executor : MarshalByRefObject { - /* TODO: - * - * Needs to be common for all AppDomains - share memory too? - * Needs to have an instance in each AppDomain, and some way of referring it. - * Need to know what AppDomain a script is in so we know where to find our instance. - * - */ + // Private instance for each script private IScript m_Script; private Dictionary Events = new Dictionary(); private bool m_Running = true; - + //private List Scripts = new List(); public Executor(IScript Script) { m_Script = Script; - } - public void StopScript() + // Object never expires + public override Object InitializeLifetimeService() { - m_Running = false; + Console.WriteLine("Executor: InitializeLifetimeService()"); + // return null; + ILease lease = (ILease)base.InitializeLifetimeService(); + + if (lease.CurrentState == LeaseState.Initial) + { + lease.InitialLeaseTime = TimeSpan.Zero; // TimeSpan.FromMinutes(1); +// lease.SponsorshipTimeout = TimeSpan.FromMinutes(2); +// lease.RenewOnCallTime = TimeSpan.FromSeconds(2); + } + return lease; } + public AppDomain GetAppDomain() { return AppDomain.CurrentDomain; @@ -40,14 +46,6 @@ namespace OpenSim.Region.ScriptEngine.Common // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead! - //foreach (MemberInfo mi in this.GetType().GetMembers()) - //{ - //if (mi.ToString().ToLower().Contains("default")) - //{ - // Console.WriteLine("Member found: " + mi.ToString()); - //} - //} - if (m_Running == false) { // Script is inactive, do not execute! @@ -97,6 +95,13 @@ namespace OpenSim.Region.ScriptEngine.Common } } + + public void StopScript() + { + m_Running = false; + } + + } } -- cgit v1.1