Exemple #1
0
func newHttpPool() *httpPool {
	this := &httpPool{}

	factory := func() (pool.Resource, error) {
		conn := &httpClient{
			pool: this,
			id:   atomic.AddUint64(&this.nextId, 1),
		}

		timeout := 3 * time.Second
		conn.Client = &http.Client{
			Transport: &http.Transport{
				Proxy: http.ProxyFromEnvironment,
				Dial: (&net.Dialer{
					Timeout:   timeout,
					KeepAlive: 60 * time.Second,
				}).Dial,
				TLSHandshakeTimeout: timeout,
			},
		}

		return conn, nil
	}

	this.pool = pool.NewResourcePool("kafka", factory,
		1000, 1000, 0, time.Second*10, time.Minute) // TODO

	return this
}
Exemple #2
0
func BenchmarkDumbPool(b *testing.B) {
	p := pool.NewResourcePool("dumbpool", PoolFactory, 100,
		100, 0, time.Hour, 0)
	for i := 0; i < b.N; i++ {
		r, e := p.Get()
		if e != nil {
			b.Fatal(e)
		}

		p.Put(r)
	}

}
Exemple #3
0
func (this *funServantPeerPool) Open() {
	factory := func() (pool.Resource, error) {
		client, err := this.connect(this.peerAddr)
		if err != nil {
			return nil, err
		}

		id := atomic.AddUint64(&this.nextServantId, 1)
		log.Debug("peer[%s] connected txn:%d", this.peerAddr, id)

		return newFunServantPeer(id, this, client), nil
	}

	this.pool = pool.NewResourcePool("peer", factory,
		this.cf.PoolCapacity, this.cf.PoolCapacity, this.cf.IdleTimeout,
		this.cf.DiagnosticInterval, this.cf.BorrowTimeout)
}