[#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>
remotes/KirillovDenis/release/v0.21.1 v0.12.0-rc1
Alex Vanin 2020-10-02 11:01:54 +03:00
parent d2009c8731
commit 861bac3892
3 changed files with 14 additions and 9 deletions

View File

@ -16,7 +16,6 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
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/services/object"
tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
"github.com/spf13/viper"
@ -39,6 +38,7 @@ const (
// config keys for cfgGRPC
cfgListenAddress = "grpc.endpoint"
cfgMaxMsgSize = "grpc.maxmessagesize"
// config keys for cfgMorph
cfgMorphRPCAddress = "morph.endpoint"
@ -58,6 +58,10 @@ const (
cfgMaxObjectSize = "node.maxobjectsize" // get value from chain
)
const (
addressSize = 72 // 32 bytes oid, 32 bytes cid, 8 bytes protobuf encoding
)
type cfg struct {
ctx context.Context
@ -166,6 +170,9 @@ func initCfg(path string) *cfg {
netAddr, err := network.AddressFromString(viperCfg.GetString(cfgBootstrapAddress))
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{
ctx: context.Background(),
viper: viperCfg,
@ -192,8 +199,8 @@ func initCfg(path string) *cfg {
maxObjectSize: viperCfg.GetUint64(cfgMaxObjectSize),
},
cfgGRPC: cfgGRPC{
maxChunkSize: object.GRPCPayloadChunkSize,
maxAddrAmount: object.GRPCSearchAddrAmount,
maxChunkSize: maxChunkSize,
maxAddrAmount: maxAddrAmount,
},
localAddr: netAddr,
}
@ -228,6 +235,7 @@ func defaultConfiguration(v *viper.Viper) {
v.SetDefault(cfgMorphRPCAddress, "http://morph_chain.localtest.nspcc.ru:30333/")
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(cfgAccountingFee, "1")

View File

@ -13,7 +13,9 @@ func initGRPC(c *cfg) {
c.cfgGRPC.listener, err = net.Listen("tcp", c.viper.GetString(cfgListenAddress))
fatalOnErr(err)
c.cfgGRPC.server = grpc.NewServer()
c.cfgGRPC.server = grpc.NewServer(
grpc.MaxSendMsgSize(c.viper.GetInt(cfgMaxMsgSize)),
)
}
func serveGRPC(c *cfg) {

View File

@ -9,11 +9,6 @@ import (
"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 (
errChunking = errors.New("can't split message to stream chunks")
)