mirror of
https://github.com/status-im/consul.git
synced 2025-01-12 14:55:02 +00:00
Reuse the results from gettimeofday(2)...
Inside of a single RPC call, reuse time.Now().
This commit is contained in:
parent
3215b8727f
commit
b391b075bd
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user