V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
simple2025
0D

为什么我的 go 实现的 tail 占用 cpu 如此之高?

  •  
  •   simple2025 · Dec 30, 2020 · 2725 views
    This topic created in 1945 days ago, the information mentioned may be changed or developed.

    https://github.com/chen19901225/gtail

    top 的结果

    
      PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                            
    27982 vagrant   20   0  707212   8096   1472 S  37.2  0.1   0:25.79 ./gtail --pattern=/tmp/*.log       
    
    

    我也 sleep 也呀

    Supplement 1  ·  Dec 30, 2020
    发现是什么问题了,代码逻辑完全是错的,居然跑起来结果对
    2 replies    2020-12-30 08:53:43 +08:00
    msg7086
        1
    msg7086  
       Dec 30, 2020 via Android   ❤️ 1
    因为没用 ionotify ?
    eudore
        2
    eudore  
       Dec 30, 2020   ❤️ 1
    不要 for 循环 open,文件读完了等 fsnotify 的信号再继续 tail 。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6151 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 02:24 · PVG 10:24 · LAX 19:24 · JFK 22:24
    ♥ Do have faith in what you're doing.