From b391b075bdf045d160dcbb195b7889e23ffd9050 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Sat, 30 Jan 2016 14:39:17 -0800 Subject: [PATCH] Reuse the results from gettimeofday(2)... Inside of a single RPC call, reuse time.Now(). --- consul/client.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/consul/client.go b/consul/client.go index b3fdb080e8..e0a9986e60 100644 --- a/consul/client.go +++ b/consul/client.go @@ -329,8 +329,10 @@ func (c *Client) localEvent(event serf.UserEvent) { // RPC is used to forward an RPC call to a consul server, or fail if no servers func (c *Client) RPC(method string, args interface{}, reply interface{}) error { // Check the last rpc time + now := time.Now() + lastRPCTime := now.Sub(c.lastRPCTime) var server *serverParts - if time.Now().Sub(c.lastRPCTime) < clientRPCCache { + if c.lastServer != nil && lastRPCTime < clientRPCConnMaxIdle { server = c.lastServer if server != nil { goto TRY_RPC @@ -358,7 +360,7 @@ TRY_RPC: // Cache the last server c.lastServer = server - c.lastRPCTime = time.Now() + c.lastRPCTime = now return nil }