开发者

How to run a python script on a Rails server?

I have a Rails server which will need to run a python script at the background. I know that I can run it like I run terminal commands in ruby, but how is the performance 开发者_JAVA百科like? is it better to use a python framework and not Rails? Is there better ways (optimization wise) to run python scripts on a Rails server?


If you mean that it needs to run periodically, just set it up as a cron job, no special performance characteristics to worry about there.

If you mean that it needs to run when pages are requested from your Ruby website, then simply running the script each time won't perform well as it needs to fire up the Python interpreter over and over again.

If the Python script is large but is only called from a relatively small number of page requests, you might be able to get away with this, sometimes it's not worth the time to optimise a slow operation that isn't called often.

If the bulk of your website is based around the functionality of the Python script, then yes, you are probably better off switching to a Python web framework and loading it as a module.

If the Python script isn't very big, then you are probably better off rewriting it in Ruby.

Worst case scenario is that the script is big and used often, but doesn't make up enough of your website to justify switching to Python. In that case, I'd consider wrapping the Python in a daemon that Ruby can talk to in the background.


You will incur the cost of starting python each time you run it from ruby. The cost would be the same in a python framework, unless you could use the python script as a library instead.


You could setup a daemon in rails to execute the python script.

http://railscasts.com/episodes/129-custom-daemon - Tutorial for setting up daemons in rails

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜