Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PSL-1196] control concurrent calls to RQService #882

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions raptorq/node/grpc/raptorq.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ const (
inputEncodeFileName = "input.data"
symbolIDFileSubDir = "meta"
symbolFileSubdir = "symbols"
concurrency = 4
)

type raptorQ struct {
conn *clientConn
client pb.RaptorQClient
config *node.Config
conn *clientConn
client pb.RaptorQClient
config *node.Config
semaphore chan struct{} // Semaphore to control concurrency
}

func randID() string {
Expand Down Expand Up @@ -136,6 +138,11 @@ func scanSymbolIDFiles(dirPath string) (map[string]node.RawSymbolIDFile, error)

// Encode data, and return a list of identifier of symbols
func (service *raptorQ) RQEncode(ctx context.Context, data []byte, id string, store rqstore.Store) (*node.Encode, error) {
service.semaphore <- struct{}{} // Acquire slot
defer func() {
<-service.semaphore // Release the semaphore slot
}()

if data == nil {
return nil, errors.Errorf("invalid data")
}
Expand Down Expand Up @@ -183,6 +190,11 @@ func (service *raptorQ) RQEncode(ctx context.Context, data []byte, id string, st
}

func (service *raptorQ) EncodeInfo(ctx context.Context, data []byte, copies uint32, blockHash string, pastelID string) (*node.EncodeInfo, error) {
service.semaphore <- struct{}{} // Acquire a semaphore slot
defer func() {
<-service.semaphore // Release the semaphore slot
}()

if data == nil {
return nil, errors.Errorf("invalid data")
}
Expand Down Expand Up @@ -270,8 +282,9 @@ func (service *raptorQ) contextWithLogPrefix(ctx context.Context) context.Contex

func newRaptorQ(conn *clientConn, config *node.Config) node.RaptorQ {
return &raptorQ{
conn: conn,
client: pb.NewRaptorQClient(conn),
config: config,
conn: conn,
client: pb.NewRaptorQClient(conn),
config: config,
semaphore: make(chan struct{}, concurrency),
}
}
Loading