dongtiaobeng7901
2018-02-02 10:16
浏览 38

时间到了.Ticker在Ubuntu 16.04 Server上意外启动

I have a very weird problem.
My ticker fires on my Ubuntu Server way more often than on my laptop.
The code I am using:

package main

import (
    "time"
    "fmt"
    "sync"
)

func main() {
    go func() {
        for m := range time.NewTicker(3 * time.Second).C {
            fmt.Printf("miner tick, %s
", m.String())
        }
    }()
    mutex := sync.Mutex{}
    mutex.Lock()
    mutex.Lock() // so main does not exit 
}

This is the output from my laptop, where the ticker behaves just fine:

miner tick, 2018-02-02 11:07:10.501114311 +0100 CET m=+3.000369091
miner tick, 2018-02-02 11:07:13.501091057 +0100 CET m=+6.000345958
miner tick, 2018-02-02 11:07:16.501129717 +0100 CET m=+9.000384497
miner tick, 2018-02-02 11:07:19.501132742 +0100 CET m=+12.000387556
miner tick, 2018-02-02 11:07:22.501124748 +0100 CET m=+15.000379558
miner tick, 2018-02-02 11:07:25.501129955 +0100 CET m=+18.000384763
miner tick, 2018-02-02 11:07:28.501074390 +0100 CET m=+21.000329347
miner tick, 2018-02-02 11:07:31.501104596 +0100 CET m=+24.000359376
miner tick, 2018-02-02 11:07:34.501126679 +0100 CET m=+27.000381460
miner tick, 2018-02-02 11:07:37.501136231 +0100 CET m=+30.000391041
miner tick, 2018-02-02 11:07:40.501064832 +0100 CET m=+33.000319616
miner tick, 2018-02-02 11:07:43.501131945 +0100 CET m=+36.000386725
miner tick, 2018-02-02 11:07:46.501099862 +0100 CET m=+39.000354648

This is the output from my Ubuntu Server:

miner tick, 2018-02-02 11:02:21.083678481 +0100 CET m=+3.000187501 // A
miner tick, 2018-02-02 11:02:09.15319572 +0100 CET m=+6.000375001
miner tick, 2018-02-02 11:02:12.15338322 +0100 CET m=+9.000562501
miner tick, 2018-02-02 11:02:15.15357072 +0100 CET m=+12.000750001
miner tick, 2018-02-02 11:02:18.15375822 +0100 CET m=+15.000937501
miner tick, 2018-02-02 11:02:21.15394572 +0100 CET m=+18.001125001
miner tick, 2018-02-02 11:02:24.15413322 +0100 CET m=+21.001312501
miner tick, 2018-02-02 11:02:27.15432072 +0100 CET m=+24.001500001
miner tick, 2018-02-02 11:02:30.15450822 +0100 CET m=+27.001687501 // B
miner tick, 2018-02-02 11:02:33.15469572 +0100 CET m=+30.001875001
miner tick, 2018-02-02 11:02:36.15888347 +0100 CET m=+33.006062751
miner tick, 2018-02-02 11:02:39.15507072 +0100 CET m=+36.002250001
miner tick, 2018-02-02 11:02:24.536503357 +0100 CET m=+39.002437501 // C
miner tick, 2018-02-02 11:02:27.536690857 +0100 CET m=+42.002625001
miner tick, 2018-02-02 11:02:30.536878357 +0100 CET m=+45.002812501
miner tick, 2018-02-02 11:02:33.537065857 +0100 CET m=+48.003000001
miner tick, 2018-02-02 11:02:36.541253607 +0100 CET m=+51.007187751

Notice the first tick A The ticks from B are printed way more rapidly than the ticks before (so definitely not within an interval of 3 seconds)
Notice the ticks from C on. All these ticks also are printed almost instantly after each other

I checked the system time on my Ubuntu server with hwclock, but that is fine and always exactly the same as on my laptop.

EDIT: output of timedatectl on my server:

    Local time: Fri 2018-02-02 11:30:50 CET
  Universal time: Fri 2018-02-02 10:30:50 UTC
        RTC time: Fri 2018-02-02 10:30:50
       Time zone: Europe/Berlin (CET, +0100)
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no

EDIT2:
simplifying the example to:

package main

import (
    "time"
    "fmt"
)

func main() {
    for {
        fmt.Println(time.Now().String())
        time.Sleep(1 * time.Second)
    }
}

output on the server:

2018-02-02 11:34:48.041731255 +0100 CET m=+0.000000001
2018-02-02 11:34:49.041793755 +0100 CET m=+1.000062501
2018-02-02 11:34:50.041856255 +0100 CET m=+2.000125001
2018-02-02 11:34:51.041918755 +0100 CET m=+3.000187501
2018-02-02 11:34:52.041981255 +0100 CET m=+4.000250001
2018-02-02 11:34:53.042043755 +0100 CET m=+5.000312501
2018-02-02 11:34:54.042106255 +0100 CET m=+6.000375001
2018-02-02 11:34:55.042168755 +0100 CET m=+7.000437501
2018-02-02 11:34:36.234756165 +0100 CET m=+8.000500001
2018-02-02 11:34:37.234818665 +0100 CET m=+9.000562501
2018-02-02 11:34:38.234881165 +0100 CET m=+10.000625001
2018-02-02 11:34:39.234943665 +0100 CET m=+11.000687501
2018-02-02 11:34:40.235006165 +0100 CET m=+12.000750001
2018-02-02 11:34:41.235068665 +0100 CET m=+13.000812501
2018-02-02 11:34:42.235131165 +0100 CET m=+14.000875001
2018-02-02 11:34:43.235193665 +0100 CET m=+15.000937501
2018-02-02 11:34:44.235256165 +0100 CET m=+16.001000001
2018-02-02 11:34:45.235318665 +0100 CET m=+17.001062501
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duandu5846 2018-02-07 08:21
    已采纳

    I found out what my problem is.
    I disabled ACPI on my Ubuntu server in order to detect all 6 gpus I am using. With ACPI on, I can only see 4 of 6 gpus (thats an issue for another question)
    With ACPI turned off, somehow my system time is no longer NTP synchronized and runs then slightly faster than my RTC, completely destroying all time dependent applications...

    So, no go issue after all (who would have thought that anyway, right? :) )

    点赞 打赏 评论

相关推荐 更多相似问题