V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
miencun
V2EX  ›  Go 编程语言

萌新问个 Goroutine 问题

  •  
  •   miencun · 2020-11-09 19:05:20 +08:00 · 1595 次点击
    这是一个创建于 1270 天前的主题,其中的信息可能已经有所发展或是发生改变。
    只有一个任务,并且是同步的,比如:拉一个 api 要等 2s|
    这个有没必要写成 Goroutine ?
    主要是性能方面有没区别。
    5 条回复    2020-11-10 10:32:49 +08:00
    unixeno
        1
    unixeno  
       2020-11-09 19:23:22 +08:00 via Android
    只有一个任务还有数据依赖的写 goroutine 干啥
    性能更差
    nulIptr
        2
    nulIptr  
       2020-11-09 20:03:15 +08:00
    只有一个任务,还要等 2 秒,还考虑啥性能问题。。。不过随手一写反正也没坏处。。。
    BoarBoar
        3
    BoarBoar  
       2020-11-09 20:12:11 +08:00
    所有异步都是解决 io 耗时的,典型就是等待网络或者 db 操作
    对 cpu 密集性任务没用,看你耗时在哪里了
    miencun
        4
    miencun  
    OP
       2020-11-10 09:28:29 +08:00
    @unixeno 只是 http 请求这一部分加 Goroutine,最终还是要 waitgroup
    koujyungenn
        5
    koujyungenn  
       2020-11-10 10:32:49 +08:00
    如果是批量请求,多个 Goroutine 我觉得性能上会好一些
    但拉一个的话....你咋写区别都不大
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1173 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 17:33 · PVG 01:33 · LAX 10:33 · JFK 13:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.