英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论