duangao7133 2015-04-17 17:05
浏览 80
已采纳

是否应该在http请求goroutine之外处理所有独立任务?

Since golang handles incoming requests in separate goroutines, it's unclear to me which types of tasks should be deferred for processing by a message queue e.g. NSQ consumers and which should be handled within the http request goroutine.

  • 写回答

1条回答 默认 最新

  • dousou1967 2015-04-18 03:57
    关注

    Since the net/http package runs each request you do not need to worry about blocking the request goroutine. The real question you should ask myself is "Do I need to do this before I return a response to the client, or can it be deferred until later". Generally if I need to fetch from a database to serve a response that will block the request goroutine, and that is ok. If I can return a response now and put a message on a queue to do stuff later, that can be ok too.

    Since the request goroutine has little cost to exist, and it is isolated from other requests, you really don't need to worry about it that much. Do what makes sense for the client.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 把Excel导入MATLAB显示错误怎么解决?
  • ¥15 Java中消息和缓存如何使用
  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx