Skip to content

Commit

Permalink
govpp-perf
Browse files Browse the repository at this point in the history
Signed-off-by: Vlado Lavor <[email protected]>
  • Loading branch information
VladoLavor committed Jan 23, 2025
1 parent f46456c commit 899e48f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
10 changes: 5 additions & 5 deletions core/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ func (ch *Channel) nextSeqNum() uint16 {
}

func (ch *Channel) newRequest(msg api.Message, multi bool) *vppRequest {
return &vppRequest{
msg: msg,
seqNum: ch.nextSeqNum(),
multi: multi,
}
request := ch.conn.requestPool.Get().(*vppRequest)
request.msg = msg
request.seqNum = ch.nextSeqNum()
request.multi = multi
return request
}

func (ch *Channel) CheckCompatiblity(msgs ...api.Message) error {
Expand Down
5 changes: 5 additions & 0 deletions core/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ type Connection struct {
msgControlPing api.Message
msgControlPingReply api.Message

requestPool sync.Pool
replyPool sync.Pool

traceLock sync.Mutex
trace *Trace // API tracer (disabled by default)
}
Expand Down Expand Up @@ -170,6 +173,8 @@ func newConnection(binapi adapter.VppAPI, attempts int, interval time.Duration,
msgControlPing: msgControlPing,
msgControlPingReply: msgControlPingReply,
channelIdPool: newIDPool(0x7fff),
requestPool: sync.Pool{New: func() interface{} { return &vppRequest{} }},
replyPool: sync.Pool{New: func() interface{} { return &vppReply{} }},
}
c.channelPool = genericpool.New[*Channel](func() *Channel {
if isDebugOn(debugOptChannels) {
Expand Down
13 changes: 7 additions & 6 deletions core/request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,15 @@ func (c *Connection) msgCallback(msgID uint16, data []byte) {
// treat this as a last part of the reply
lastReplyReceived := isMulti && msgID == c.pingReplyID

reply := c.replyPool.Get().(*vppReply)
reply.msgID = msgID
reply.seqNum = seqNum
reply.data = append([]byte(nil), data...)
reply.lastReceived = lastReplyReceived

// send the data to the channel, it needs to be copied,
// because it will be freed after this function returns
sendReply(ch, &vppReply{
msgID: msgID,
seqNum: seqNum,
data: append([]byte(nil), data...),
lastReceived: lastReplyReceived,
})
sendReply(ch, reply)

// store actual time of this reply
c.lastReplyLock.Lock()
Expand Down
6 changes: 5 additions & 1 deletion core/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (s *Stream) SendMsg(msg api.Message) error {
if err := s.conn.processRequest(s.channel, req); err != nil {
return err
}
s.conn.requestPool.Put(req)
s.Lock()
s.pkgPath = s.conn.GetMessagePath(msg)
s.Unlock()
Expand All @@ -216,9 +217,12 @@ func (s *Stream) RecvMsg() (api.Message, error) {
// allocate message instance
msg = reflect.New(reflect.TypeOf(msg).Elem()).Interface().(api.Message)
// decode message data
if err := s.channel.msgCodec.DecodeMsg(reply.data, msg); err != nil {
if err = s.channel.msgCodec.DecodeMsg(reply.data, msg); err != nil {
return nil, err
}
reply.err = nil
s.conn.replyPool.Put(reply)

return msg, nil
}

Expand Down

0 comments on commit 899e48f

Please sign in to comment.