[#59] Use max msg size in transport server and splitter
For GRPC it is about 4 MiB. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
d2009c8731
commit
861bac3892
3 changed files with 14 additions and 9 deletions
|
@ -16,7 +16,6 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||||
nmwrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
nmwrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object"
|
|
||||||
tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
|
tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -39,6 +38,7 @@ const (
|
||||||
|
|
||||||
// config keys for cfgGRPC
|
// config keys for cfgGRPC
|
||||||
cfgListenAddress = "grpc.endpoint"
|
cfgListenAddress = "grpc.endpoint"
|
||||||
|
cfgMaxMsgSize = "grpc.maxmessagesize"
|
||||||
|
|
||||||
// config keys for cfgMorph
|
// config keys for cfgMorph
|
||||||
cfgMorphRPCAddress = "morph.endpoint"
|
cfgMorphRPCAddress = "morph.endpoint"
|
||||||
|
@ -58,6 +58,10 @@ const (
|
||||||
cfgMaxObjectSize = "node.maxobjectsize" // get value from chain
|
cfgMaxObjectSize = "node.maxobjectsize" // get value from chain
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
addressSize = 72 // 32 bytes oid, 32 bytes cid, 8 bytes protobuf encoding
|
||||||
|
)
|
||||||
|
|
||||||
type cfg struct {
|
type cfg struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
|
||||||
|
@ -166,6 +170,9 @@ func initCfg(path string) *cfg {
|
||||||
netAddr, err := network.AddressFromString(viperCfg.GetString(cfgBootstrapAddress))
|
netAddr, err := network.AddressFromString(viperCfg.GetString(cfgBootstrapAddress))
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
|
||||||
|
maxChunkSize := viperCfg.GetUint64(cfgMaxMsgSize) * 3 / 4 // 25% to meta, 75% to payload
|
||||||
|
maxAddrAmount := maxChunkSize / addressSize // each address is about 72 bytes
|
||||||
|
|
||||||
return &cfg{
|
return &cfg{
|
||||||
ctx: context.Background(),
|
ctx: context.Background(),
|
||||||
viper: viperCfg,
|
viper: viperCfg,
|
||||||
|
@ -192,8 +199,8 @@ func initCfg(path string) *cfg {
|
||||||
maxObjectSize: viperCfg.GetUint64(cfgMaxObjectSize),
|
maxObjectSize: viperCfg.GetUint64(cfgMaxObjectSize),
|
||||||
},
|
},
|
||||||
cfgGRPC: cfgGRPC{
|
cfgGRPC: cfgGRPC{
|
||||||
maxChunkSize: object.GRPCPayloadChunkSize,
|
maxChunkSize: maxChunkSize,
|
||||||
maxAddrAmount: object.GRPCSearchAddrAmount,
|
maxAddrAmount: maxAddrAmount,
|
||||||
},
|
},
|
||||||
localAddr: netAddr,
|
localAddr: netAddr,
|
||||||
}
|
}
|
||||||
|
@ -228,6 +235,7 @@ func defaultConfiguration(v *viper.Viper) {
|
||||||
|
|
||||||
v.SetDefault(cfgMorphRPCAddress, "http://morph_chain.localtest.nspcc.ru:30333/")
|
v.SetDefault(cfgMorphRPCAddress, "http://morph_chain.localtest.nspcc.ru:30333/")
|
||||||
v.SetDefault(cfgListenAddress, "127.0.0.1:50501") // listen address
|
v.SetDefault(cfgListenAddress, "127.0.0.1:50501") // listen address
|
||||||
|
v.SetDefault(cfgMaxMsgSize, 4<<20) // transport msg limit 4 MiB
|
||||||
|
|
||||||
v.SetDefault(cfgAccountingContract, "1aeefe1d0dfade49740fff779c02cd4a0538ffb1")
|
v.SetDefault(cfgAccountingContract, "1aeefe1d0dfade49740fff779c02cd4a0538ffb1")
|
||||||
v.SetDefault(cfgAccountingFee, "1")
|
v.SetDefault(cfgAccountingFee, "1")
|
||||||
|
|
|
@ -13,7 +13,9 @@ func initGRPC(c *cfg) {
|
||||||
c.cfgGRPC.listener, err = net.Listen("tcp", c.viper.GetString(cfgListenAddress))
|
c.cfgGRPC.listener, err = net.Listen("tcp", c.viper.GetString(cfgListenAddress))
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
|
||||||
c.cfgGRPC.server = grpc.NewServer()
|
c.cfgGRPC.server = grpc.NewServer(
|
||||||
|
grpc.MaxSendMsgSize(c.viper.GetInt(cfgMaxMsgSize)),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveGRPC(c *cfg) {
|
func serveGRPC(c *cfg) {
|
||||||
|
|
|
@ -9,11 +9,6 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
GRPCPayloadChunkSize = 1024 * 1024 * 3 // 4 MiB is a max limit, 3 MiB should be okay
|
|
||||||
GRPCSearchAddrAmount = 1024 * 32 // 64 bytes per addr, in total about 2 MiB
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errChunking = errors.New("can't split message to stream chunks")
|
errChunking = errors.New("can't split message to stream chunks")
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue