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

Addressing issue #41 - maxSyncConcurrency environment variable #63

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

smeyerhot
Copy link

Fixes #41

Motivation

This commit allows users to specify an env variable MAXSYNC which overrides DefaultConcurrency in rosetta-sdk-go.

Solution

The solution was to add a field to the Configuration struct in the same way as Mode and Network. Then used this value when constructing the syncer to override defaults.

Open questions

@smeyerhot smeyerhot changed the title Addressing issue #41 - maxSyncConcurrency enviroment variable Addressing issue #41 - maxSyncConcurrency environment variable Dec 25, 2020
@smeyerhot
Copy link
Author

This is a revised PR, same fix but cleared up some issues with the Dockerfile.

@@ -62,6 +62,7 @@ func TestIndexer_Pruning(t *testing.T) {
Network: bitcoin.MainnetNetwork,
Blockchain: bitcoin.Blockchain,
},
MaxSyncConcurrency: 1,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will default to 4 but will also cap out there. Might want set back to 256.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

case "0":
return nil, errors.New("syncer concurrency must be greater than zero")
default:
config.MaxSyncConcurrency, _ = strconv.ParseInt(maxSyncValue, 10, 64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should explicitly handle this parsing error

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled in new commit.

Note: Allowed for MAXSYNC to not be set and default to 256

go.mod Outdated




Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these extra lines

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@@ -229,6 +231,8 @@ func Initialize(
coinCache: map[string]*types.AccountCoin{},
coinCacheMutex: new(sdkUtils.PriorityMutex),
seenSemaphore: semaphore.NewWeighted(int64(runtime.NumCPU())),
maxSync: config.MaxSyncConcurrency,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@@ -180,6 +195,7 @@ func LoadConfiguration(baseDirectory string) (*Configuration, error) {
}
config.GenesisBlockIdentifier = bitcoin.TestnetGenesisBlockIdentifier
config.Params = bitcoin.TestnetParams

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

README.md Outdated
@@ -61,25 +70,25 @@ at port `8080`.

#### Mainnet:Online
```text
docker run -d --rm --ulimit "nofile=100000:100000" -v "$(pwd)/bitcoin-data:/data" -e "MODE=ONLINE" -e "NETWORK=MAINNET" -e "PORT=8080" -p 8080:8080 -p 8333:8333 rosetta-bitcoin:latest
docker run -d --rm --ulimit "nofile=100000:100000" -v "$(pwd)/bitcoin-data:/data" -e "MAXSYNC"="256" -e "MODE=ONLINE" -e "NETWORK=MAINNET" -e "PORT=8080" -p 8080:8080 -p 8333:8333 rosetta-bitcoin:latest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "MAXSYNC=256"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Dockerfile Outdated
@@ -48,6 +48,7 @@ ENV GOLANG_VERSION 1.15.5
ENV GOLANG_DOWNLOAD_SHA256 9a58494e8da722c3aef248c9227b0e9c528c7318309827780f16220998180a0d
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Dockerfile Outdated
@@ -85,7 +86,6 @@ COPY --from=bitcoind-builder /app/bitcoind /app/bitcoind

# Copy binary from rosetta-builder
COPY --from=rosetta-builder /app/* /app/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: removed line unnecessarily

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added back in.

return nil, errors.New("syncer concurrency must be greater than zero")
default:
config.MaxSyncConcurrency = parsedValue
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expression on line 148 is equivalent to:

!(err == nil || defaultMaxSync)

if we want to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Allow max concurrency limits configuration on the indexer
2 participants