Example #1
0
func (p *Pool) addInstanceMux(s skynet.ServiceInfo) {
	if _, ok := p.servicePools[s.AddrString()]; !ok {
		sp := &servicePool{
			service: s,
			pool: pools.NewResourcePool(func() (pools.Resource, error) {
				c, err := conn.NewConnection(s.Name, GetNetwork(), s.AddrString(), DIAL_TIMEOUT)

				if err == nil {
					c.SetIdleTimeout(getIdleTimeout(s))
				}

				return c, err
			},
				getIdleConnectionsToInstance(s),
				getMaxConnectionsToInstance(s)),
		}

		p.servicePools[s.AddrString()] = sp
	} else {
		p.UpdateInstance(s)
	}
}
Example #2
0
func (c *Client) getServicePool(instance *skynet.ServiceInfo) (sp *servicePool) {
	servicePoolMutex.Lock()
	defer servicePoolMutex.Unlock()

	key := getInstanceKey(instance)

	var ok bool
	if sp, ok = c.servicePools[key]; ok {
		return
	}

	dbgf("making service pool, size = %d, %d\n",
		c.Config.IdleConnectionsToInstance, c.Config.MaxConnectionsToInstance)

	sp = &servicePool{
		service: instance,
		pool: pools.NewResourcePool(getConnectionFactory(instance),
			c.Config.IdleConnectionsToInstance,
			c.Config.MaxConnectionsToInstance),
	}
	return
}