Ticker does not ticks at exact intervals. TTL Keys expire

252 views
Skip to first unread message

nav...@freshdesk.com

unread,
Mar 28, 2016, 8:50:32 PM3/28/16
to golang-nuts

I have built a ticker of 10 seconds duration and listening to its channel inside a for-select-case.

start = time.Now()
for {
select {
case <-tick.C:
end = time.Now()
log.Debug("time span ", end.Sub(start))

The time span that I see printed are usually 10 seconds.
But randomly it is off by a very large margin 20-40 seconds.
This causes my system to go haywire due to the keys in etcd 
getting expired after their TTL expire in 20 sec.



Dave Cheney

unread,
Mar 28, 2016, 9:27:58 PM3/28/16
to golang-nuts, nav...@freshdesk.com
Is your test system running inside a virtual machine ?

Peter Weinberger

unread,
Mar 28, 2016, 9:30:16 PM3/28/16
to nav...@freshdesk.com, golang-nuts
what operating system? More precisely, are you running on OSX?


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave Cheney

unread,
Mar 28, 2016, 9:34:39 PM3/28/16
to golang-nuts, nav...@freshdesk.com
time.Ticker is not specified to tick on a specific interval, only after a specific interval. However being off by multiple seconds is outside the observed behaviour for this method. Can you please provide a runnable sample that demonstrates the issue.

Thanks.


On Tuesday, 29 March 2016 11:50:32 UTC+11, nav...@freshdesk.com wrote:

Navneet Kumar

unread,
Mar 29, 2016, 3:13:21 AM3/29/16
to Dave Cheney, golang-nuts
I am running this on aws c4.xlarge machine with amazon linux.

I supposed the update is taking more time than the timer so I timed them as well.
Here is the log

Mar 29 06:07:59.927 [INF] master_service.go:267 time span : 20.448122623s Updated entry in : 517.139µs
Mar 29 06:08:06.530 [INF] master_service.go:267 time span : 6.603211053s Updated entry in : 2.440108719s
Mar 29 06:08:34.071 [INF] master_service.go:267 time span : 14.592913681s Updated entry in : 383.052µs


I am attaching the standalone code. This seems to work fine.
The actual one is running along with lots of goroutines.


  
--
---
Navneet Kumar
updateRedis.go

Navneet Kumar

unread,
Mar 30, 2016, 8:04:58 AM3/30/16
to Dave Cheney, golang-nuts
Hi Dave,

I have also noticed large delay in order of 10s of seconds between channel send and receive of two goroutines.
Could this be the cause as timer sends the ticks from channel.


I have created a channel and passed it to two different goroutines.
The first goroutine receives data from zmq socket and passes on to the other goroutine for processing.

I am passing the pointer to the following struct in the channel

type mydata struct {
    data []byte
    tm time.Time
}

At the receiving goroutine I am printing time.Since(mydata.tm)

 
 


--
---
Navneet Kumar

James Bardin

unread,
Mar 30, 2016, 8:58:19 AM3/30/16
to golang-nuts, da...@cheney.net, nav...@freshdesk.com

Does your program seem to take an excessive amount of CPU during these delays? If you have a goroutine that ends up in a busy loop it can starve the scheduler, causing timing issues.

Navneet Kumar

unread,
Mar 30, 2016, 9:11:15 AM3/30/16
to James Bardin, golang-nuts, Dave Cheney
No. It hardly crosses 5%.
--
---
Navneet Kumar

Florin Pățan

unread,
Mar 30, 2016, 7:59:53 PM3/30/16
to golang-nuts
Can you please post a code which reproduces the issue? And do you have millions of goroutines running? Very large heap / too much garbage / too much garbage collection going on?
Reply all
Reply to author
Forward
0 new messages