예제 #1
0
파일: pool.go 프로젝트: bubble66/skynet
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)
	}
}
예제 #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
}