Skip to content

Commit

Permalink
reduce number of locking operations
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Nov 25, 2024
1 parent f9d313f commit cac6f4f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/lmd/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,23 @@ func (res *Response) WriteDataResponse(json *jsoniter.Stream) {

// WriteDataResponseRowLocked appends each row but locks the peer before doing so. We don't have to lock for each column then.
func (res *Response) WriteDataResponseRowLocked(json *jsoniter.Stream) {
for i := range res.RawResults.DataResult {
var curPeer *Peer
for i, row := range res.RawResults.DataResult {
if i > 0 {
json.WriteRaw(",\n")
}
row := res.RawResults.DataResult[i]
row.DataStore.Peer.lock.RLock()
if curPeer != row.DataStore.Peer {
if curPeer != nil {
curPeer.lock.RUnlock()
}
curPeer = row.DataStore.Peer
curPeer.lock.RLock()
}
row.WriteJSON(json, res.Request.RequestColumns)
row.DataStore.Peer.lock.RUnlock()
}

if curPeer != nil {
curPeer.lock.RUnlock()
}
}

Expand Down

0 comments on commit cac6f4f

Please sign in to comment.