运行守护进程服务器还是Shell命令?

huangapple go评论78阅读模式
英文:

Run daemon server or shell command?

问题

我需要验证电话号码,并且有一个非常好的Python库可以做到这一点。然而,我的技术栈是Go,我真的不想转移一个非常庞大的库。你认为是通过在Go代码库内部运行一个shell命令来使用Python库,还是运行一个守护进程然后以某种方式与之通信更好呢?

英文:

I need to validate phone numbers and there is a very good python library that will do this. My stack however is Go and I'm really not looking forward to porting a very large library. Do you think it would be better to use the python library by running a shell command from within the Go codebase or by running a daemon that I then have to communicate with somehow?

答案1

得分: 2

Python作为一种解释型语言,每次从命令行运行脚本时都需要加载解释器。此外,

在我的特定系统上,在磁盘缓存之后,执行一个带有import string的脚本需要20毫秒的时间(这对于你的用例来说是合理的)。如果你正在处理大量信息,并且不能一次性提交所有信息,你应该考虑设置一个守护进程来避免这种开销。

另一方面,编写和测试守护进程更加复杂,因此在过早进行优化之前,你应该先看看脚本是否满足你的需求。

对于你的问题,没有一个适用于所有情况的答案。最终,你总是需要使用你的数据和系统来测试性能。

英文:

Python, being an interpreted language, requires the system to load the interpreter each time a script is run from the command line. Also

On my particular system, after disk caching, it takes the system 20ms to execute a script with import string (which is plausible for your use case). If you're processing a lot information, and can't submit it all at once, you should consider setting up a daemon to avoid this kind of overhead.

On the other hand, a daemon is more complex to write and test, so you should probably see if a script suits your needs before optimizing prematurely.

There's no answer to your question that fits every possible case. Ultimately, you always have to try the performance with your data and in your system,

huangapple
  • 本文由 发表于 2014年4月23日 02:04:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/23227044.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定