{"action":"opened","issue":{"url":"https://api.github.com/repos/hpcloud/tail/issues/95","repository_url":"https://api.github.com/repos/hpcloud/tail","labels_url":"https://api.github.com/repos/hpcloud/tail/issues/95/labels{/name}","comments_url":"https://api.github.com/repos/hpcloud/tail/issues/95/comments","events_url":"https://api.github.com/repos/hpcloud/tail/issues/95/events","html_url":"https://github.com/hpcloud/tail/issues/95","id":164811242,"number":95,"title":"tailFile: leakybucket algo err","user":{"login":"henrystark","id":3928709,"avatar_url":"https://avatars.githubusercontent.com/u/3928709?v=3","gravatar_id":"","url":"https://api.github.com/users/henrystark","html_url":"https://github.com/henrystark","followers_url":"https://api.github.com/users/henrystark/followers","following_url":"https://api.github.com/users/henrystark/following{/other_user}","gists_url":"https://api.github.com/users/henrystark/gists{/gist_id}","starred_url":"https://api.github.com/users/henrystark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/henrystark/subscriptions","organizations_url":"https://api.github.com/users/henrystark/orgs","repos_url":"https://api.github.com/users/henrystark/repos","events_url":"https://api.github.com/users/henrystark/events{/privacy}","received_events_url":"https://api.github.com/users/henrystark/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-11T10:58:54Z","updated_at":"2016-07-11T10:58:54Z","closed_at":null,"body":"https://github.com/hpcloud/tail/blob/master/ratelimiter/leakybucket.go\r\n\r\ntype LeakyBucket struct {\r\n\tSize         uint16\r\n        Burst       uint16  \r\n\tFill         float64\r\n\tLeakInterval time.Duration // time.Duration for 1 unit of size to leak\r\n\tLastupdate   time.Time\r\n\tNow          func() time.Time\r\n}\r\n\r\nfunc (b *LeakyBucket) updateFill() {\r\n\tnow := b.Now()\r\n\tif b.Fill > 0 {\r\n\t\telapsed := now.Sub(b.Lastupdate)\r\n\r\n\t\tb.Fill -= float64(elapsed) / float64(b.LeakInterval)\r\n\t\tif b.Fill < 0 {\r\n\t\t\tb.Fill = 0\r\n\t\t}\r\n\t}\r\n\tb.Lastupdate = now\r\n}\r\n\r\nfunc (b *LeakyBucket) Pour(amount uint16) bool {\r\n\tb.updateFill()\r\n\r\n\tvar newfill float64 = b.Fill + float64(amount)\r\n\r\n\tif newfill > float64(b.Size) {\r\n\t\treturn false\r\n\t}\r\n\r\n\tb.Fill = newfill\r\n\r\n\treturn true\r\n}\r\n\r\nnewfill float64 = b.Fill + float64(amount)\r\nb.Fill -= float64(elapsed) / float64(b.LeakInterval)\r\nit is strange: add amount, dec time ?!\r\n\r\nshould be:\r\n\r\nfunc (b *LeakyBucket) updateFill() {\r\n\tnow := b.Now()\r\n\tif b.Fill > 0 {\r\n\t\telapsed := now.Sub(b.Lastupdate)\r\n\r\n\t\tb.Fill -= float(b.Size) * float64(elapsed) / float64(b.LeakInterval)\r\n\t\tif b.Fill < 0 {\r\n\t\t\tb.Fill = 0\r\n\t\t}\r\n\t}\r\n\tb.Lastupdate = now\r\n}\r\n\r\nfunc (b *LeakyBucket) Pour(amount uint16) bool {\r\n\tb.updateFill()\r\n\r\n\tvar newfill float64 = b.Fill + float64(amount)\r\n\r\n\tif newfill > float64(b.Burst) {\r\n\t\treturn false\r\n\t}\r\n\r\n\tb.Fill = newfill\r\n\r\n\treturn true\r\n}\r\n\r\nplease see: https://en.wikipedia.org/wiki/Leaky_bucket#Parameters  \r\n\r\n\r\n"}}
{"actor":{"display_login":"henrystark"}}