netpool test. wip
This commit is contained in:
@@ -3,12 +3,14 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/yudhasubki/netpool"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
)
|
||||
|
||||
@@ -154,14 +156,23 @@ func (p *SyncedPool) SpawnRemoteGrain(id CartId, host string) {
|
||||
}
|
||||
|
||||
go func(i CartId, h string) {
|
||||
remote, err := NewRemoteGrain(i, h)
|
||||
if err != nil {
|
||||
log.Printf("Error creating remote grain %v", err)
|
||||
var pool netpool.Netpooler
|
||||
p.mu.RLock()
|
||||
for _, r := range p.remotes {
|
||||
if r.Host == h {
|
||||
pool = r.HostPool
|
||||
break
|
||||
}
|
||||
}
|
||||
p.mu.RUnlock()
|
||||
if pool == nil {
|
||||
log.Printf("Error spawning remote grain, no pool for %s", h)
|
||||
return
|
||||
}
|
||||
remoteGrain := NewRemoteGrain(i, h, pool)
|
||||
|
||||
p.mu.Lock()
|
||||
p.remoteIndex[i] = remote
|
||||
p.remoteIndex[i] = remoteGrain
|
||||
p.mu.Unlock()
|
||||
}(id, host)
|
||||
}
|
||||
@@ -181,7 +192,7 @@ func (p *SyncedPool) HandleHostError(host string) {
|
||||
|
||||
func NewSyncedPool(local *GrainLocalPool, hostname string, discovery Discovery) (*SyncedPool, error) {
|
||||
listen := fmt.Sprintf("%s:1338", hostname)
|
||||
conn := NewConnection(listen)
|
||||
conn := NewConnection(listen, nil)
|
||||
server, err := conn.Listen()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -381,9 +392,17 @@ func (p *SyncedPool) AddRemote(host string) {
|
||||
return
|
||||
}
|
||||
|
||||
client := NewConnection(fmt.Sprintf("%s:1338", host))
|
||||
host_pool, err := netpool.New(func() (net.Conn, error) {
|
||||
return net.Dial("tcp", fmt.Sprintf("%s:1338", host))
|
||||
}, netpool.WithMaxPool(256))
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Error creating pool: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := NewConnection(fmt.Sprintf("%s:1338", host), host_pool)
|
||||
|
||||
var err error
|
||||
pings := 3
|
||||
for pings >= 0 {
|
||||
_, err = client.Call(Ping, nil)
|
||||
@@ -397,7 +416,12 @@ func (p *SyncedPool) AddRemote(host string) {
|
||||
}
|
||||
log.Printf("Connected to remote %s", host)
|
||||
|
||||
cart_pool, err := netpool.New(func() (net.Conn, error) {
|
||||
return net.Dial("tcp", fmt.Sprintf("%s:1337", host))
|
||||
}, netpool.WithMaxPool(512))
|
||||
|
||||
remote := RemoteHost{
|
||||
HostPool: cart_pool,
|
||||
Connection: client,
|
||||
MissedPings: 0,
|
||||
Host: host,
|
||||
|
||||
Reference in New Issue
Block a user