Files
fn-serverless/api/datastore
Reed Allman 88635fcf08 remove usage of time.After (#1498)
* remove usage of time.After

these little guys leak in the background, it's easy enough to remove usage of
them altogether. this reduces cpu load on fn, the main culprit was the one in
waitHot which polls every 200ms. if you run a load test where functions get a
slot and exec a lot faster than 200ms then these things pile up kinda quickly.

* common.NewTimer

this covers up the hole left by the stdlib timer, see: https://golang.org/pkg/time/#Timer.Reset
and changes all usage of time.NewTimer to use common.NewTimer for posterity,
should anyone decide to start calling reset on any timers where we previously
were not, this should make them safe. we'll have to catch new timers in
review.

see comment by rsc
https://github.com/golang/go/issues/14038#issuecomment-219909704 for details
about the thorny side effects of the stdlib handling this behavior (namely,
that the returned value of Reset's behavior could change). in any case, this
is desirable for our use case from what I can tell in all cases, as we're not
particularly interested in the return value from Stop nor Reset.

* replace the timer instead of resetting

since the Reset contract for the timer is messed up, if we wrap the timer and
implement reset by just making a new timer we can get the behavior we want
without having to dance around in the caller making sure we stop timers in any
of our loops before resetting them, since Reset is supposed to behave this
way anyway. and with this, so long as we defer stop it will stop the last
assigned timer. so I think this checks out
2019-05-08 15:14:40 -07:00
..
2019-05-08 15:14:40 -07:00