开发者

RESTful Webservice with embedded IronPython: engine & scope questions

I have a RESTful C# web service (using Open Rasta) that I want to run IronPython scripts that talk to a CouchDB.

One thing I could use some 开发者_如何转开发clarification on is: How often do I need a new instance of the python engine and the scope? one each per application? per session? per request?

I currently have a static engine at the application level along with a dictionary of compiled scripts; then, per request, I create a new scope and execute the code within that scope...

Is that correct? thread safe? and as performant as it could be?

EDIT: regarding the bounty Please also answer the question I posed in reply to Jeff: Will a static instance of the engine cause sequential requests from different clients to wait in line to execute? if so I will probably need everything on a per-request basis.


A ScriptRuntime/ScriptEngine per application and a Scope per request is exactly how it should be done. Runtimes/Engine are thread-safe and Scopes are not.


Per request is the way to go unless all of your code is thread safe. You may get better performance using per application (per session implies you have th notion of "sesions" between you client and server), however the implication there is that all of your code in the "application" is thread safe.

So per-request is what you should use unless you know your code to be thread safe.

Note also that per application will be faster only if:

  1. In order to make things thread safe you've not blocking threads in any way.
  2. To a certain extent if the business layer/data layer are extremely "heavy" (take a lot of time to instantiate) then some performance benefit may be gained.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜