Skip to content

Commit

Permalink
Merge pull request #19 from PowerLoom/feat/configurable-pool-limits
Browse files Browse the repository at this point in the history
Feat/configurable pool limits
  • Loading branch information
anomit authored Oct 17, 2024
2 parents 99e23cc + 00466a6 commit cb7ef87
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
4 changes: 3 additions & 1 deletion config/settings.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"SignerAccountAddress": "SIGNER_ACCOUNT_ADDRESS",
"LocalCollectorPort": "LOCAL_COLLECTOR_PORT",
"TrustedRelayersListUrl" : "TRUSTED_RELAYERS_LIST_URL",
"DataMarketAddress" : "DATA_MARKET_CONTRACT"
"DataMarketAddress" : "DATA_MARKET_CONTRACT",
"MaxStreamPoolSize" : MAX_STREAM_POOL_SIZE,
"StreamPoolHealthCheckInterval" : STREAM_POOL_HEALTH_CHECK_INTERVAL
}
10 changes: 10 additions & 0 deletions config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Settings struct {
PortNumber string `json:"LocalCollectorPort"`
TrustedRelayersListUrl string `json:"TrustedRelayersListUrl"`
DataMarketAddress string `json:"DataMarketAddress"`
MaxStreamPoolSize int `json:"MaxStreamPoolSize"`
StreamPoolHealthCheckInterval int `json:"StreamPoolHealthCheckInterval"`
}

func LoadConfig() {
Expand All @@ -45,5 +47,13 @@ func LoadConfig() {
config.TrustedRelayersListUrl = "https://raw.githubusercontent.com/PowerLoom/snapshotter-lite-local-collector/feat/trusted-relayers/relayers.json"
}

// Set default values for new fields if not specified in the config file
if config.MaxStreamPoolSize == 0 {
config.MaxStreamPoolSize = 2 // Default to 2 as per your current setup
}
if config.StreamPoolHealthCheckInterval == 0 {
config.StreamPoolHealthCheckInterval = 30 // Default to 30 seconds
}

SettingsObj = &config
}
3 changes: 2 additions & 1 deletion pkgs/service/libp2p_stream_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"context"
"proto-snapshot-server/config"
"sync"
"time"

Expand Down Expand Up @@ -63,7 +64,7 @@ func (p *streamPool) Stop() {
}

func (p *streamPool) maintainPool(ctx context.Context) {
ticker := time.NewTicker(900 * time.Second)
ticker := time.NewTicker(time.Duration(config.SettingsObj.StreamPoolHealthCheckInterval) * time.Second)
defer ticker.Stop()

for {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/service/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func NewMsgServerImpl() pkgs.SubmissionServer {
return stream, nil
}
return &server{
streamPool: newStreamPool(1024, sequencerID, createStream), // Adjust pool size as needed
streamPool: newStreamPool(config.SettingsObj.MaxStreamPoolSize, sequencerID, createStream),
}
}

Expand Down
6 changes: 5 additions & 1 deletion server_autofill.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ if [ -z "$DATA_MARKET_CONTRACT" ]; then
exit 1;
fi

export MAX_STREAM_POOL_SIZE="${MAX_STREAM_POOL_SIZE:-2}"
export STREAM_POOL_HEALTH_CHECK_INTERVAL="${STREAM_POOL_HEALTH_CHECK_INTERVAL:-30}"
cd config

# Template to actual settings.json manipulation
Expand All @@ -35,7 +37,9 @@ sed -i'.backup' -e "s#POWERLOOM_REPORTING_URL#$POWERLOOM_REPORTING_URL#" \
-e "s#LOCAL_COLLECTOR_PORT#$LOCAL_COLLECTOR_PORT#" \
-e "s#RELAYER_PRIVATE_KEY#$RELAYER_PRIVATE_KEY#" settings.json \
-e "s#TRUSTED_RELAYERS_LIST_URL#$TRUSTED_RELAYERS_LIST_URL#" settings.json \
-e "s#DATA_MARKET_CONTRACT#$DATA_MARKET_CONTRACT#" settings.json
-e "s#DATA_MARKET_CONTRACT#$DATA_MARKET_CONTRACT#" settings.json \
-e "s#MAX_STREAM_POOL_SIZE#$MAX_STREAM_POOL_SIZE#" settings.json \
-e "s#STREAM_POOL_HEALTH_CHECK_INTERVAL#$STREAM_POOL_HEALTH_CHECK_INTERVAL#" settings.json

# Cleanup backup file
rm settings.json.backup

0 comments on commit cb7ef87

Please sign in to comment.