Go语言库中的HTTP服务器是非阻塞的吗?

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

Is the http server in the go libraries nonblocking?

问题

我想要一个非阻塞的HTTP服务器,用于我的Go项目的RESTful端点。Go库中的服务器是否能满足要求?

英文:

I want a nonblocking http server for restful endpoints for my go project. Will the server included in the go libs do the trick?

答案1

得分: 3

Go的http包是并发的,而不是像Node.js那样的非阻塞。这意味着即使请求处理程序执行阻塞操作,它也不会延迟其他请求的处理。正如Dave C所说,它为每个请求创建一个新的goroutine。实际上,这意味着你可以享受非阻塞服务器的好处,而不需要担心你编写的代码是否会阻塞。

英文:

The Go http package is concurrent, rather than nonblocking in the node.js sense. This means that the request handlers will not delay the processing of other requests even if they perform blocking operations. As Dave C said, it creates a new goroutine for each request. In practice, this means that you get the benefits of a nonblocking server without needing to worry about whether the code you write is blocking.

huangapple
  • 本文由 发表于 2015年5月9日 22:54:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/30141392.html
匿名

发表评论

匿名网友

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

确定