github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/msg/consumer/config.go (about) 1 // Copyright (c) 2018 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package consumer 22 23 import ( 24 "time" 25 26 "github.com/m3db/m3/src/msg/protocol/proto" 27 "github.com/m3db/m3/src/x/instrument" 28 "github.com/m3db/m3/src/x/pool" 29 ) 30 31 // Configuration configs the consumer options. 32 type Configuration struct { 33 Encoder *proto.Configuration `yaml:"encoder"` 34 Decoder *proto.Configuration `yaml:"decoder"` 35 MessagePool *MessagePoolConfiguration `yaml:"messagePool"` 36 AckFlushInterval *time.Duration `yaml:"ackFlushInterval"` 37 AckBufferSize *int `yaml:"ackBufferSize"` 38 ConnectionWriteBufferSize *int `yaml:"connectionWriteBufferSize"` 39 ConnectionReadBufferSize *int `yaml:"connectionReadBufferSize"` 40 ConnectionWriteTimeout *time.Duration `yaml:"connectionWriteTimeout"` 41 } 42 43 // MessagePoolConfiguration is the message pool configuration 44 // options, which extends the default object pool configuration. 45 type MessagePoolConfiguration struct { 46 // Size is the size of the pool. 47 Size pool.Size `yaml:"size"` 48 49 // Watermark is the object pool watermark configuration. 50 Watermark pool.WatermarkConfiguration `yaml:"watermark"` 51 52 // MaxBufferReuseSize specifies the maximum buffer which can 53 // be reused and pooled, if a buffer greater than this 54 // is used then it is discarded. Zero specifies no limit. 55 MaxBufferReuseSize int `yaml:"maxBufferReuseSize"` 56 } 57 58 // NewOptions creates message pool options. 59 func (c MessagePoolConfiguration) NewOptions( 60 iopts instrument.Options, 61 ) MessagePoolOptions { 62 poolCfg := pool.ObjectPoolConfiguration{ 63 Size: c.Size, 64 Watermark: c.Watermark, 65 } 66 return MessagePoolOptions{ 67 PoolOptions: poolCfg.NewObjectPoolOptions(iopts), 68 MaxBufferReuseSize: c.MaxBufferReuseSize, 69 } 70 } 71 72 // NewOptions creates consumer options. 73 func (c *Configuration) NewOptions(iOpts instrument.Options) Options { 74 opts := NewOptions().SetInstrumentOptions(iOpts) 75 if c.Encoder != nil { 76 opts = opts.SetEncoderOptions(c.Encoder.NewOptions(iOpts)) 77 } 78 if c.Decoder != nil { 79 opts = opts.SetDecoderOptions(c.Decoder.NewOptions(iOpts)) 80 } 81 if c.MessagePool != nil { 82 opts = opts.SetMessagePoolOptions(c.MessagePool.NewOptions(iOpts)) 83 } 84 if c.AckFlushInterval != nil { 85 opts = opts.SetAckFlushInterval(*c.AckFlushInterval) 86 } 87 if c.AckBufferSize != nil { 88 opts = opts.SetAckBufferSize(*c.AckBufferSize) 89 } 90 if c.ConnectionWriteBufferSize != nil { 91 opts = opts.SetConnectionWriteBufferSize(*c.ConnectionWriteBufferSize) 92 } 93 if c.ConnectionReadBufferSize != nil { 94 opts = opts.SetConnectionReadBufferSize(*c.ConnectionReadBufferSize) 95 } 96 if c.ConnectionWriteTimeout != nil { 97 opts = opts.SetConnectionWriteTimeout(*c.ConnectionWriteTimeout) 98 } 99 return opts 100 }