diff --git a/README.md b/README.md index bf79aa52..db15690d 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,11 @@ ### Go-IPLD-Prime -`go-graphsync` relies on `go-ipld-prime` to traverse IPLD Selectors in an IPLD graph. `go-ipld-prime` implements the [IPLD specification](https://github.com/ipld/specs) in go and is an alternative to older implementations such as `go-ipld-format` and `go-ipld-cbor`. In order to use `go-graphsync`, some understanding and use of `go-ipld-prime` concepts is necessary. - -If your existing library (i.e. `go-ipfs` or `go-filecoin`) uses these other older libraries, you can largely use go-graphsync without switching to `go-ipld-prime` across your codebase, but it will require some translations +`go-graphsync` relies on `go-ipld-prime` to traverse IPLD Selectors in an IPLD graph. `go-ipld-prime` implements the [IPLD specification](https://ipld.io/specs/) in go and is an alternative to older implementations such as `go-ipld-format` and `go-ipld-cbor`. In order to use `go-graphsync`, some understanding and use of `go-ipld-prime` concepts is necessary. ## Install -`go-graphsync` requires Go >= 1.13 and can be installed using Go modules +`go-graphsync` requires Go >= 1.19 and can be installed using Go modules ## Usage @@ -120,6 +118,27 @@ type ResponseProgress struct { The above provides both immediate and relevant metadata for matching nodes in a traversal, and is very similar to the information provided by a local IPLD selector traversal in `go-ipld-prime` +## Production Configuration + +go-graphsync supports a number of configuration options. Each configuration option is documented in [the code](./impl/graphsync.go). The default configuration is not well setup for production clients or servers serving high traffic volumes. We supply a default set of "production defaults" that are more appropriately suited to this use case. You can use them as such: + +```golang +import ( + graphsync "github.com/ipfs/go-graphsync/impl" + gsnet "github.com/ipfs/go-graphsync/network" + ipld "github.com/ipld/go-ipld-prime" +) + +var ctx context.Context +var host libp2p.Host +var lsys ipld.LinkSystem + +network := gsnet.NewFromLibp2pHost(host) +exchange := graphsync.New(ctx, network, lsys, graphsync.ProductionDefaults) +``` + +If you are running GraphSync in a production environment, it is recommended to take time to understand configuration settings and adjust them appropriately for your particular use case. + ## Contribute PRs are welcome! diff --git a/impl/graphsync.go b/impl/graphsync.go index 0b1e036d..ac3c43af 100644 --- a/impl/graphsync.go +++ b/impl/graphsync.go @@ -200,6 +200,20 @@ func PanicCallback(callbackFn panics.CallBackFn) Option { } } +// ProductionDefaults are a set of alternate defaults for clients and servers +// with large resources that want to serve heavy loads +var ProductionDefaults = func(gs *graphsyncConfigOptions) { + MaxInProgressIncomingRequests(200)(gs) + MaxInProgressOutgoingRequests(200)(gs) + MaxMemoryResponder(8 << 30)(gs) + MaxMemoryPerPeerResponder(32 << 20)(gs) + MaxInProgressIncomingRequestsPerPeer(20)(gs) + MessageSendRetries(2)(gs) + SendMessageTimeout(2 * time.Minute)(gs) + MaxLinksPerIncomingRequests(32 * (1 << 20))(gs) + MaxLinksPerOutgoingRequests(32 * (1 << 20))(gs) +} + // New creates a new GraphSync Exchange on the given network, // and the given link loader+storer. func New(parent context.Context, network gsnet.GraphSyncNetwork,