dongwei2030 2018-10-24 13:58
浏览 63
已采纳

是否不挂接所有可用的CPU电源?

I know, most of the beginners of go ask how to have performative go-routines / concurrency, this point I passed a few weeks ago. :-)

I have a real fast trans-coder that uses every cycle available of my 4+4 (i7 HT) CPU. It reads a file into a slice of pointers to structs, does calculations on these and writes the result back to disk. I am using bufio. I am coming from VB so the performance of Go is unbelievable.

I tried to add minimal sleeps (via time.Sleep()), but that drastically decreased performance.

While my trans-coder is working the whole system is lagging. I must change the go task's priority to low or idle to be able to work again.

How could I implement something that keeps the system responsive?

Right now I start thousands of go-routines (loop over a slice of pointers). Should I limit the number of routines?

  • 写回答

2条回答 默认 最新

  • dongshen3352 2018-10-24 14:00
    关注

    Lowering the process priority is arguably the correct way to do this. Use your OS's scheduler. That's what it's for. Per this question you can start your process with a specified priority like so:

    start "MyApp" /low "C:\myapp.exe"
    

    You may also be able to set process priority from within the application per this question:

    err := syscall.Setpriority(syscall.Getpid(), -1, -1)
    

    Lastly, you can use GOMAXPROCS to configure how many CPUs the process is allowed to use. You can pass it in as an environment variable at runtime, or call runtime.GOMAXPROCS() within your code to override it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条