-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client pool 6718ea378b80e1066aa30589885e3e728910c1c1
- Loading branch information
Showing
18 changed files
with
245 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package grpc | ||
|
||
import ( | ||
"github.com/jhump/protoreflect/desc" | ||
"github.com/jhump/protoreflect/dynamic/grpcdynamic" | ||
"github.com/yandex/pandora/core/clientpool" | ||
) | ||
|
||
type SharedDeps struct { | ||
services map[string]desc.MethodDescriptor | ||
clientPool *clientpool.Pool[grpcdynamic.Stub] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package clientpool | ||
|
||
import ( | ||
"errors" | ||
"sync/atomic" | ||
) | ||
|
||
func New[T any](size int) (*Pool[T], error) { | ||
if size <= 0 { | ||
return nil, errors.New("pool size must be greater than zero") | ||
} | ||
return &Pool[T]{ | ||
pool: make([]T, 0, size), | ||
}, nil | ||
} | ||
|
||
type Pool[T any] struct { | ||
pool []T | ||
i atomic.Uint64 | ||
} | ||
|
||
func (p *Pool[T]) Add(conn T) { | ||
p.pool = append(p.pool, conn) | ||
} | ||
|
||
func (p *Pool[T]) Next() T { | ||
if len(p.pool) == 0 { | ||
var zero T | ||
return zero | ||
} | ||
i := p.i.Add(1) | ||
return p.pool[int(i)%len(p.pool)] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.