netpool test. wip
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 32s
Build and Publish / BuildAndDeploy (push) Successful in 3m2s

This commit is contained in:
matst80
2024-11-21 21:23:38 +01:00
parent 1f7f161e62
commit 5348c33f3b
11 changed files with 140 additions and 89 deletions

View File

@@ -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,