forked from TrueCloudLab/frostfs-node
[#694] cmd/neofs-node: Reuse single instance of client cache in all components
This will reduce amount of open connections up to 3 times. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
38afb82926
commit
fd24a99533
4 changed files with 14 additions and 21 deletions
|
@ -11,9 +11,11 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||||
|
apiclient "github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||||
netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
||||||
|
apiclientconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/apiclient"
|
||||||
contractsconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/contracts"
|
contractsconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/contracts"
|
||||||
engineconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine"
|
engineconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine"
|
||||||
shardconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard"
|
shardconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard"
|
||||||
|
@ -36,6 +38,7 @@ import (
|
||||||
netmap2 "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
netmap2 "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/timer"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/timer"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/network/cache"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
||||||
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
|
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
|
||||||
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
|
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
|
||||||
|
@ -108,6 +111,8 @@ type cfg struct {
|
||||||
cfgReputation cfgReputation
|
cfgReputation cfgReputation
|
||||||
|
|
||||||
mainChainClient *client.Client
|
mainChainClient *client.Client
|
||||||
|
|
||||||
|
clientCache *cache.ClientCache
|
||||||
}
|
}
|
||||||
|
|
||||||
type cfgGRPC struct {
|
type cfgGRPC struct {
|
||||||
|
@ -271,12 +276,17 @@ func initCfg(path string) *cfg {
|
||||||
scriptHash: contractsconfig.Reputation(appCfg),
|
scriptHash: contractsconfig.Reputation(appCfg),
|
||||||
workerPool: reputationWorkerPool,
|
workerPool: reputationWorkerPool,
|
||||||
},
|
},
|
||||||
|
clientCache: cache.NewSDKClientCache(
|
||||||
|
apiclient.WithDialTimeout(apiclientconfig.DialTimeout(appCfg)),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
if metricsconfig.Address(c.appCfg) != "" {
|
if metricsconfig.Address(c.appCfg) != "" {
|
||||||
c.metricsCollector = metrics.NewStorageMetrics()
|
c.metricsCollector = metrics.NewStorageMetrics()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.onShutdown(c.clientCache.CloseAll) // clean up connections
|
||||||
|
|
||||||
initLocalStorage(c)
|
initLocalStorage(c)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
|
containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/network/cache"
|
|
||||||
containerTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/container/grpc"
|
containerTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/container/grpc"
|
||||||
containerService "github.com/nspcc-dev/neofs-node/pkg/services/container"
|
containerService "github.com/nspcc-dev/neofs-node/pkg/services/container"
|
||||||
loadcontroller "github.com/nspcc-dev/neofs-node/pkg/services/container/announcement/load/controller"
|
loadcontroller "github.com/nspcc-dev/neofs-node/pkg/services/container/announcement/load/controller"
|
||||||
|
@ -72,15 +71,13 @@ func initContainerService(c *cfg) {
|
||||||
PlacementBuilder: loadPlacementBuilder,
|
PlacementBuilder: loadPlacementBuilder,
|
||||||
})
|
})
|
||||||
|
|
||||||
clientCache := cache.NewSDKClientCache() // FIXME: use shared cache
|
|
||||||
|
|
||||||
loadRouter := loadroute.New(
|
loadRouter := loadroute.New(
|
||||||
loadroute.Prm{
|
loadroute.Prm{
|
||||||
LocalServerInfo: c,
|
LocalServerInfo: c,
|
||||||
RemoteWriterProvider: &remoteLoadAnnounceProvider{
|
RemoteWriterProvider: &remoteLoadAnnounceProvider{
|
||||||
key: &c.key.PrivateKey,
|
key: &c.key.PrivateKey,
|
||||||
loadAddrSrc: c,
|
loadAddrSrc: c,
|
||||||
clientCache: clientCache,
|
clientCache: c.clientCache,
|
||||||
deadEndProvider: loadcontroller.SimpleWriterProvider(loadAccumulator),
|
deadEndProvider: loadcontroller.SimpleWriterProvider(loadAccumulator),
|
||||||
},
|
},
|
||||||
Builder: routeBuilder,
|
Builder: routeBuilder,
|
||||||
|
@ -88,8 +85,6 @@ func initContainerService(c *cfg) {
|
||||||
loadroute.WithLogger(c.log),
|
loadroute.WithLogger(c.log),
|
||||||
)
|
)
|
||||||
|
|
||||||
c.onShutdown(clientCache.CloseAll)
|
|
||||||
|
|
||||||
ctrl := loadcontroller.New(
|
ctrl := loadcontroller.New(
|
||||||
loadcontroller.Prm{
|
loadcontroller.Prm{
|
||||||
LocalMetrics: loadcontroller.SimpleIteratorProvider(localMetrics),
|
LocalMetrics: loadcontroller.SimpleIteratorProvider(localMetrics),
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/util/signature"
|
"github.com/nspcc-dev/neofs-api-go/util/signature"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
objectGRPC "github.com/nspcc-dev/neofs-api-go/v2/object/grpc"
|
objectGRPC "github.com/nspcc-dev/neofs-api-go/v2/object/grpc"
|
||||||
apiclientconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/apiclient"
|
|
||||||
policerconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/policer"
|
policerconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/policer"
|
||||||
replicatorconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/replicator"
|
replicatorconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/replicator"
|
||||||
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||||
|
@ -25,7 +24,6 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/network/cache"
|
|
||||||
objectTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/object/grpc"
|
objectTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/object/grpc"
|
||||||
objectService "github.com/nspcc-dev/neofs-node/pkg/services/object"
|
objectService "github.com/nspcc-dev/neofs-node/pkg/services/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/acl"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/acl"
|
||||||
|
@ -168,17 +166,12 @@ func initObjectService(c *cfg) {
|
||||||
|
|
||||||
nodeOwner.SetNeo3Wallet(neo3Wallet)
|
nodeOwner.SetNeo3Wallet(neo3Wallet)
|
||||||
|
|
||||||
clientCache := cache.NewSDKClientCache(
|
|
||||||
client.WithDialTimeout(apiclientconfig.DialTimeout(c.appCfg)))
|
|
||||||
|
|
||||||
c.onShutdown(clientCache.CloseAll)
|
|
||||||
|
|
||||||
clientConstructor := &reputationClientConstructor{
|
clientConstructor := &reputationClientConstructor{
|
||||||
log: c.log,
|
log: c.log,
|
||||||
nmSrc: c.cfgObject.netMapStorage,
|
nmSrc: c.cfgObject.netMapStorage,
|
||||||
netState: c.cfgNetmap.state,
|
netState: c.cfgNetmap.state,
|
||||||
trustStorage: c.cfgReputation.localTrustStorage,
|
trustStorage: c.cfgReputation.localTrustStorage,
|
||||||
basicConstructor: clientCache,
|
basicConstructor: c.clientCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
coreConstructor := (*coreClientConstructor)(clientConstructor)
|
coreConstructor := (*coreClientConstructor)(clientConstructor)
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
rtpwrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
rtpwrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/network/cache"
|
|
||||||
grpcreputation "github.com/nspcc-dev/neofs-node/pkg/network/transport/reputation/grpc"
|
grpcreputation "github.com/nspcc-dev/neofs-node/pkg/network/transport/reputation/grpc"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||||
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||||
|
@ -87,15 +86,11 @@ func initReputationService(c *cfg) {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
apiClientCache := cache.NewSDKClientCache()
|
|
||||||
|
|
||||||
c.onShutdown(apiClientCache.CloseAll)
|
|
||||||
|
|
||||||
remoteLocalTrustProvider := common.NewRemoteTrustProvider(
|
remoteLocalTrustProvider := common.NewRemoteTrustProvider(
|
||||||
common.RemoteProviderPrm{
|
common.RemoteProviderPrm{
|
||||||
LocalAddrSrc: c,
|
LocalAddrSrc: c,
|
||||||
DeadEndProvider: daughterStorageWriterProvider,
|
DeadEndProvider: daughterStorageWriterProvider,
|
||||||
ClientCache: apiClientCache,
|
ClientCache: c.clientCache,
|
||||||
WriterProvider: localreputation.NewRemoteProvider(
|
WriterProvider: localreputation.NewRemoteProvider(
|
||||||
localreputation.RemoteProviderPrm{
|
localreputation.RemoteProviderPrm{
|
||||||
Key: &c.key.PrivateKey,
|
Key: &c.key.PrivateKey,
|
||||||
|
@ -108,7 +103,7 @@ func initReputationService(c *cfg) {
|
||||||
common.RemoteProviderPrm{
|
common.RemoteProviderPrm{
|
||||||
LocalAddrSrc: c,
|
LocalAddrSrc: c,
|
||||||
DeadEndProvider: consumerStorageWriterProvider,
|
DeadEndProvider: consumerStorageWriterProvider,
|
||||||
ClientCache: apiClientCache,
|
ClientCache: c.clientCache,
|
||||||
WriterProvider: intermediatereputation.NewRemoteProvider(
|
WriterProvider: intermediatereputation.NewRemoteProvider(
|
||||||
intermediatereputation.RemoteProviderPrm{
|
intermediatereputation.RemoteProviderPrm{
|
||||||
Key: &c.key.PrivateKey,
|
Key: &c.key.PrivateKey,
|
||||||
|
|
Loading…
Reference in a new issue