Golang的HTTP服务器请求是异步还是同步的?

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

Golang HTTP server requests async or sync?

问题

我有一个使用Golang编写的RESTful API,我的Angular网站调用它。

Go的http模块默认是按顺序处理请求还是并发处理请求?

另外,如果我的Go中的HandlerFunc调用一个Python脚本,对该HandlerFunc的并发调用会生成多个Python进程,还是会被阻塞直到一个进程完成?

英文:

I have a RESTful API in Golang that my Angular website calls.

Does the Go http module by default handle requests in sequence or concurrently?

Also, if my HandlerFunc in Go calls a python script, would concurrent calls to this HandlerFunc spawn multiple python processes, or would they be blocked till one is complete?

答案1

得分: 4

是的,默认情况下,所有的HTTP请求都可以并发执行。

如果你正在执行一个Python脚本,那么确实会生成一个单独的进程,并且它们会并发执行。

请注意,这可能会带来生成过多进程并耗尽资源的潜在风险。

英文:

Yes, by default all http requests can be executed concurrently.

If you are executing a python script, then indeed a separate process will be spawned and they will execute concurrently.

Please note that this carries the potential risk of spawning too many processes and running out of resources.

huangapple
  • 本文由 发表于 2017年7月10日 14:07:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/45004791.html
匿名

发表评论

匿名网友

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

确定