Skip to content

Commit

Permalink
Remove unncessary locking in encoder
Browse files Browse the repository at this point in the history
The encoder is already protected by the wal.mu on all paths. Removing
this lock yields up to 20% more throughput when measured with etcdctl check
perf.

Signed-off-by: Thomas Jungblut <[email protected]>
  • Loading branch information
tjungblu committed Nov 30, 2022
1 parent 898415d commit bd5fbda
Showing 1 changed file with 0 additions and 7 deletions.
7 changes: 0 additions & 7 deletions server/storage/wal/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"hash"
"io"
"os"
"sync"

"go.etcd.io/etcd/pkg/v3/crc"
"go.etcd.io/etcd/pkg/v3/ioutil"
Expand All @@ -32,7 +31,6 @@ import (
const walPageBytes = 8 * minSectorSize

type encoder struct {
mu sync.Mutex
bw *ioutil.PageWriter

crc hash.Hash32
Expand Down Expand Up @@ -60,9 +58,6 @@ func newFileEncoder(f *os.File, prevCrc uint32) (*encoder, error) {
}

func (e *encoder) encode(rec *walpb.Record) error {
e.mu.Lock()
defer e.mu.Unlock()

e.crc.Write(rec.Data)
rec.Crc = e.crc.Sum32()
var (
Expand Down Expand Up @@ -108,8 +103,6 @@ func encodeFrameSize(dataBytes int) (lenField uint64, padBytes int) {
}

func (e *encoder) flush() error {
e.mu.Lock()
defer e.mu.Unlock()
return e.bw.Flush()
}

Expand Down

0 comments on commit bd5fbda

Please sign in to comment.