Documentation
¶
Index ¶
- func CalculateWeight(rtt int) int
- func Hash(key uint64, buckets int32) int32
- func HashString(s string) uint64
- func JumpConsistentHash(len int, options ...interface{}) int
- func Ping(host string) (rtt int, err error)
- type CMap
- type ConsistentAddrStrFunction
- type ConsulClientSelector
- func (s *ConsulClientSelector) AllClients(clientCodecFunc rpcx.ClientCodecFunc) []*core.Client
- func (s *ConsulClientSelector) HandleFailedClient(client *core.Client)
- func (s *ConsulClientSelector) Select(clientCodecFunc rpcx.ClientCodecFunc, options ...interface{}) (*core.Client, error)
- func (s *ConsulClientSelector) SetClient(c *rpcx.Client)
- func (s *ConsulClientSelector) SetSelectMode(sm rpcx.SelectMode)
- type EtcdClientSelector
- func (s *EtcdClientSelector) AllClients(clientCodecFunc rpcx.ClientCodecFunc) []*core.Client
- func (s *EtcdClientSelector) HandleFailedClient(client *core.Client)
- func (s *EtcdClientSelector) Select(clientCodecFunc rpcx.ClientCodecFunc, options ...interface{}) (*core.Client, error)
- func (s *EtcdClientSelector) SetClient(c *rpcx.Client)
- func (s *EtcdClientSelector) SetSelectMode(sm rpcx.SelectMode)
- type EtcdV3ClientSelector
- func (s *EtcdV3ClientSelector) AllClients(clientCodecFunc rpcx.ClientCodecFunc) []*core.Client
- func (s *EtcdV3ClientSelector) HandleFailedClient(client *core.Client)
- func (s *EtcdV3ClientSelector) Select(clientCodecFunc rpcx.ClientCodecFunc, options ...interface{}) (*core.Client, error)
- func (s *EtcdV3ClientSelector) SetClient(c *rpcx.Client)
- func (s *EtcdV3ClientSelector) SetSelectMode(sm rpcx.SelectMode)
- type HashServiceAndArgs
- type MultiClientSelector
- func (s *MultiClientSelector) AllClients(clientCodecFunc rpcx.ClientCodecFunc) []*core.Client
- func (s *MultiClientSelector) HandleFailedClient(client *core.Client)
- func (s *MultiClientSelector) Select(clientCodecFunc rpcx.ClientCodecFunc, options ...interface{}) (*core.Client, error)
- func (s *MultiClientSelector) SelectPeer(options ...interface{}) (*ServerPeer, error)
- func (s *MultiClientSelector) SetClient(c *rpcx.Client)
- func (s *MultiClientSelector) SetSelectMode(sm rpcx.SelectMode)
- type ServerPeer
- type Weighted
- type ZooKeeperClientSelector
- func (s *ZooKeeperClientSelector) AllClients(clientCodecFunc rpcx.ClientCodecFunc) []*core.Client
- func (s *ZooKeeperClientSelector) HandleFailedClient(client *core.Client)
- func (s *ZooKeeperClientSelector) Select(clientCodecFunc rpcx.ClientCodecFunc, options ...interface{}) (*core.Client, error)
- func (s *ZooKeeperClientSelector) SetClient(c *rpcx.Client)
- func (s *ZooKeeperClientSelector) SetSelectMode(sm rpcx.SelectMode)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateWeight ¶
CalculateWeight converts the rtt to weighted by:
- weight=191 if t <= 10
- weight=201 -t if 10 < t <=200
- weight=1 if 200 < t < 1000
- weight = 0 if t >= 1000
It means servers that ping time t < 10 will be preferred and servers won't be selected if t > 1000. It is hard coded based on Ops experience.
func Hash ¶
Hash consistently chooses a hash bucket number in the range [0, numBuckets) for the given key. numBuckets must be >= 1.
func JumpConsistentHash ¶
JumpConsistentHash selects a server by serviceMethod and args
Types ¶
type ConsistentAddrStrFunction ¶
type ConsistentAddrStrFunction func(options ...interface{}) string
ConsistentFunction define a hash function Return service address, like "tcp@127.0.0.1:8970"
type ConsulClientSelector ¶
type ConsulClientSelector struct { ConsulAddress string Servers []*api.AgentService WeightedServers []*Weighted ServiceName string SelectMode rpcx.SelectMode HashServiceAndArgs HashServiceAndArgs Client *rpcx.Client // contains filtered or unexported fields }
ConsulClientSelector is used to select a rpc server from consul. This registry is experimental and has not been test.
func NewConsulClientSelector ¶
func NewConsulClientSelector(consulAddress string, serviceName string, sessionTimeout time.Duration, sm rpcx.SelectMode, dailTimeout time.Duration) *ConsulClientSelector
NewConsulClientSelector creates a ConsulClientSelector
func (*ConsulClientSelector) AllClients ¶
func (s *ConsulClientSelector) AllClients(clientCodecFunc rpcx.ClientCodecFunc) []*core.Client
AllClients returns core.Clients to all servers
func (*ConsulClientSelector) HandleFailedClient ¶
func (s *ConsulClientSelector) HandleFailedClient(client *core.Client)
func (*ConsulClientSelector) Select ¶
func (s *ConsulClientSelector) Select(clientCodecFunc rpcx.ClientCodecFunc, options ...interface{}) (*core.Client, error)
Select returns a rpc client
func (*ConsulClientSelector) SetClient ¶
func (s *ConsulClientSelector) SetClient(c *rpcx.Client)
SetClient set a Client in order that clientSelector can uses it
func (*ConsulClientSelector) SetSelectMode ¶
func (s *ConsulClientSelector) SetSelectMode(sm rpcx.SelectMode)
SetSelectMode sets SelectMode
type EtcdClientSelector ¶
type EtcdClientSelector struct { EtcdServers []string KeysAPI client.KeysAPI BasePath string //should endwith serviceName Servers []string Group string Latitude float64 Longitude float64 WeightedServers []*Weighted SelectMode rpcx.SelectMode HashServiceAndArgs HashServiceAndArgs Client *rpcx.Client // contains filtered or unexported fields }
EtcdClientSelector is used to select a rpc server from etcd.
func NewEtcdClientSelector ¶
func NewEtcdClientSelector(etcdServers []string, servicePath string, sessionTimeout time.Duration, sm rpcx.SelectMode, dailTimeout time.Duration) *EtcdClientSelector
NewEtcdClientSelector creates a EtcdClientSelector
func (*EtcdClientSelector) AllClients ¶
func (s *EtcdClientSelector) AllClients(clientCodecFunc rpcx.ClientCodecFunc) []*core.Client
AllClients returns core.Clients to all servers
func (*EtcdClientSelector) HandleFailedClient ¶
func (s *EtcdClientSelector) HandleFailedClient(client *core.Client)
func (*EtcdClientSelector) Select ¶
func (s *EtcdClientSelector) Select(clientCodecFunc rpcx.ClientCodecFunc, options ...interface{}) (*core.Client, error)
Select returns a rpc client
func (*EtcdClientSelector) SetClient ¶
func (s *EtcdClientSelector) SetClient(c *rpcx.Client)
SetClient set a Client in order that clientSelector can uses it
func (*EtcdClientSelector) SetSelectMode ¶
func (s *EtcdClientSelector) SetSelectMode(sm rpcx.SelectMode)
SetSelectMode sets SelectMode
type EtcdV3ClientSelector ¶
type EtcdV3ClientSelector struct { EtcdServers []string KeysAPI *clientv3.Client BasePath string //should endwith serviceName Servers []string Group string Latitude float64 Longitude float64 WeightedServers []*Weighted SelectMode rpcx.SelectMode HashServiceAndArgs HashServiceAndArgs Client *rpcx.Client DialTimeout time.Duration Username string Password string UpdateIntervalNum int64 // contains filtered or unexported fields }
EtcdV3ClientSelector is used to select a rpc server from etcd via V3 API.
func NewEtcdV3ClientSelector ¶
func NewEtcdV3ClientSelector(etcdServers []string, servicePath string, sessionTimeout time.Duration, sm rpcx.SelectMode, dailTimeout time.Duration) *EtcdV3ClientSelector
NewEtcdClientSelector creates a EtcdClientSelector
func (*EtcdV3ClientSelector) AllClients ¶
func (s *EtcdV3ClientSelector) AllClients(clientCodecFunc rpcx.ClientCodecFunc) []*core.Client
AllClients returns core.Clients to all servers
func (*EtcdV3ClientSelector) HandleFailedClient ¶
func (s *EtcdV3ClientSelector) HandleFailedClient(client *core.Client)
func (*EtcdV3ClientSelector) Select ¶
func (s *EtcdV3ClientSelector) Select(clientCodecFunc rpcx.ClientCodecFunc, options ...interface{}) (*core.Client, error)
Select returns a rpc client
func (*EtcdV3ClientSelector) SetClient ¶
func (s *EtcdV3ClientSelector) SetClient(c *rpcx.Client)
SetClient set a Client in order that clientSelector can uses it
func (*EtcdV3ClientSelector) SetSelectMode ¶
func (s *EtcdV3ClientSelector) SetSelectMode(sm rpcx.SelectMode)
SetSelectMode sets SelectMode
type HashServiceAndArgs ¶
HashServiceAndArgs define a hash function
type MultiClientSelector ¶
type MultiClientSelector struct { Servers []*ServerPeer WeightedServers []*Weighted SelectMode rpcx.SelectMode HashServiceAndArgs HashServiceAndArgs Client *rpcx.Client // contains filtered or unexported fields }
MultiClientSelector is used to select a direct rpc server from a list.
func NewMultiClientSelector ¶
func NewMultiClientSelector(servers []*ServerPeer, sm rpcx.SelectMode, dailTimeout time.Duration) *MultiClientSelector
NewMultiClientSelector creates a MultiClientSelector
func (*MultiClientSelector) AllClients ¶
func (s *MultiClientSelector) AllClients(clientCodecFunc rpcx.ClientCodecFunc) []*core.Client
AllClients returns core.Clients to all servers
func (*MultiClientSelector) HandleFailedClient ¶
func (s *MultiClientSelector) HandleFailedClient(client *core.Client)
func (*MultiClientSelector) Select ¶
func (s *MultiClientSelector) Select(clientCodecFunc rpcx.ClientCodecFunc, options ...interface{}) (*core.Client, error)
Select returns a rpc client
func (*MultiClientSelector) SelectPeer ¶
func (s *MultiClientSelector) SelectPeer(options ...interface{}) (*ServerPeer, error)
SelectPeer returns a ServerPeer
func (*MultiClientSelector) SetClient ¶
func (s *MultiClientSelector) SetClient(c *rpcx.Client)
SetClient set a Client in order that clientSelector can uses it
func (*MultiClientSelector) SetSelectMode ¶
func (s *MultiClientSelector) SetSelectMode(sm rpcx.SelectMode)
SetSelectMode sets SelectMode
type ZooKeeperClientSelector ¶
type ZooKeeperClientSelector struct { ZKServers []string BasePath string //should endwith serviceName Servers []string Group string Latitude float64 Longitude float64 WeightedServers []*Weighted SelectMode rpcx.SelectMode HashServiceAndArgs HashServiceAndArgs ConsistentAddrStrFunction ConsistentAddrStrFunction Client *rpcx.Client // contains filtered or unexported fields }
ZooKeeperClientSelector is used to select a rpc server from zookeeper.
func NewZooKeeperClientSelector ¶
func NewZooKeeperClientSelector(zkServers []string, basePath string, sessionTimeout time.Duration, sm rpcx.SelectMode, dailTimeout time.Duration, group string) *ZooKeeperClientSelector
NewZooKeeperClientSelector creates a ZooKeeperClientSelector sessionTimeout is timeout configuration for zookeeper. timeout is timeout configuration for TCP connection to RPC servers.
func NewZooKeeperClientSelectorWithZKConn ¶
func NewZooKeeperClientSelectorWithZKConn(zkConn *zk.Conn, basePath string, sessionTimeout time.Duration, sm rpcx.SelectMode, dailTimeout time.Duration, group string) *ZooKeeperClientSelector
NewZooKeeperClientSelectorWithZKConn creates a ZooKeeperClientSelector with a shared zk connection. sessionTimeout is timeout configuration for zookeeper. timeout is timeout configuration for TCP connection to RPC servers.
func (*ZooKeeperClientSelector) AllClients ¶
func (s *ZooKeeperClientSelector) AllClients(clientCodecFunc rpcx.ClientCodecFunc) []*core.Client
AllClients returns core.Clients to all servers
func (*ZooKeeperClientSelector) HandleFailedClient ¶
func (s *ZooKeeperClientSelector) HandleFailedClient(client *core.Client)
func (*ZooKeeperClientSelector) Select ¶
func (s *ZooKeeperClientSelector) Select(clientCodecFunc rpcx.ClientCodecFunc, options ...interface{}) (*core.Client, error)
Select returns a rpc client
func (*ZooKeeperClientSelector) SetClient ¶
func (s *ZooKeeperClientSelector) SetClient(c *rpcx.Client)
SetClient sets a Client in order that clientSelector can uses it
func (*ZooKeeperClientSelector) SetSelectMode ¶
func (s *ZooKeeperClientSelector) SetSelectMode(sm rpcx.SelectMode)
SetSelectMode sets SelectMode