[IronPython] Multi threaded engine

Christos Pavlides ncichris at gmail.com
Mon Jun 7 19:55:21 CEST 2010

Thanks Jeff,
This is the recommendation I was expecting to get. 
I will run a high concurrency test on a single engine and single compiled
code, with new scopes for each request and see where it takes me.
Do I need any locks on the engine itself when Getting the scope (which could
be called from many threads at the same time)?

I have another question related to performance.
Right now I have a number of parameters that I need to pass to the
CompiledCode and I use Microsoft.Scripting.ScopeStorage.SetValue and then
create the scope using this.
Is there a more efficient way to pass parameters to the CompiledCode? Like
creating an single "parameter" object which is well known by both the
IronPython code and my C# code?


-----Original Message-----
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Jeff Hardy
Sent: Monday, June 07, 2010 6:09 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Multi threaded engine

On Mon, Jun 7, 2010 at 7:14 AM, Christos Pavlides <ncichris at gmail.com>
> I am thinking that it could be better if the ScriptEngine and CompiledCode
> are thread safe, and if I create one static engine an one static
> CompliledCode then this will minimize the compile time since the rules
> have to be compiled one time and then reused for all threads.

My understanding is that this is the case - for NWSGI I use a single
engine (per AppDomain, but that's not important) and each script is
compiled once into a CompiledCode object. On each request it gets a
new scope from the engine, finds the CompiledCode for the requested
script, and executes it in that scope. IIS can have a lot of worker
threads handling requests at any time, so it's basically the same
scenario you have. As long as you don't reuse scopes (and they're very
cheap to create) you should be just fine.

- Jeff
Users mailing list
Users at lists.ironpython.com

More information about the Ironpython-users mailing list