Reuse the results from gettimeofday(2)...

Inside of a single RPC call, reuse time.Now().
This commit is contained in:
Sean Chittenden 2016-01-30 14:39:17 -08:00
parent 3215b8727f
commit b391b075bd

View File

@ -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 // 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 { func (c *Client) RPC(method string, args interface{}, reply interface{}) error {
// Check the last rpc time // Check the last rpc time
now := time.Now()
lastRPCTime := now.Sub(c.lastRPCTime)
var server *serverParts var server *serverParts
if time.Now().Sub(c.lastRPCTime) < clientRPCCache { if c.lastServer != nil && lastRPCTime < clientRPCConnMaxIdle {
server = c.lastServer server = c.lastServer
if server != nil { if server != nil {
goto TRY_RPC goto TRY_RPC
@ -358,7 +360,7 @@ TRY_RPC:
// Cache the last server // Cache the last server
c.lastServer = server c.lastServer = server
c.lastRPCTime = time.Now() c.lastRPCTime = now
return nil return nil
} }