mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-07 19:30:22 -05:00
Reland: limit write concurrency of leveldb to max open file handles limit
This commit is contained in:
+13
-5
@@ -22,9 +22,10 @@ func toChunkKey(r ref.Ref) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type LevelDBStore struct {
|
type LevelDBStore struct {
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
mu *sync.Mutex
|
mu *sync.Mutex
|
||||||
putCount int // for testing
|
putCount int // for testing
|
||||||
|
concurrentWriteLimit chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLevelDBStore(dir string, maxFileHandles int) *LevelDBStore {
|
func NewLevelDBStore(dir string, maxFileHandles int) *LevelDBStore {
|
||||||
@@ -34,10 +35,15 @@ func NewLevelDBStore(dir string, maxFileHandles int) *LevelDBStore {
|
|||||||
Compression: opt.NoCompression,
|
Compression: opt.NoCompression,
|
||||||
Filter: filter.NewBloomFilter(10), // 10 bits/key
|
Filter: filter.NewBloomFilter(10), // 10 bits/key
|
||||||
OpenFilesCacheCapacity: maxFileHandles,
|
OpenFilesCacheCapacity: maxFileHandles,
|
||||||
WriteBuffer: 1 << 24, // 16MiB
|
WriteBuffer: 1 << 24, // 16MiB,
|
||||||
})
|
})
|
||||||
d.Chk.NoError(err)
|
d.Chk.NoError(err)
|
||||||
return &LevelDBStore{db, &sync.Mutex{}, 0}
|
return &LevelDBStore{
|
||||||
|
db,
|
||||||
|
&sync.Mutex{},
|
||||||
|
0,
|
||||||
|
make(chan struct{}, maxFileHandles),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LevelDBStore) Root() ref.Ref {
|
func (l *LevelDBStore) Root() ref.Ref {
|
||||||
@@ -86,9 +92,11 @@ func (l *LevelDBStore) Put(c Chunk) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
l.concurrentWriteLimit <- struct{}{}
|
||||||
err := l.db.Put(toChunkKey(c.Ref()), c.Data(), nil)
|
err := l.db.Put(toChunkKey(c.Ref()), c.Data(), nil)
|
||||||
d.Chk.NoError(err)
|
d.Chk.NoError(err)
|
||||||
l.putCount += 1
|
l.putCount += 1
|
||||||
|
<-l.concurrentWriteLimit
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LevelDBStore) Close() error {
|
func (l *LevelDBStore) Close() error {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func (suite *LevelDBStoreTestSuite) SetupTest() {
|
|||||||
var err error
|
var err error
|
||||||
suite.dir, err = ioutil.TempDir(os.TempDir(), "")
|
suite.dir, err = ioutil.TempDir(os.TempDir(), "")
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
store := NewLevelDBStore(suite.dir, 0)
|
store := NewLevelDBStore(suite.dir, 24)
|
||||||
suite.putCountFn = func() int {
|
suite.putCountFn = func() int {
|
||||||
return store.putCount
|
return store.putCount
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-6
@@ -23,16 +23,15 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type httpServer struct {
|
type httpServer struct {
|
||||||
cs chunks.ChunkStore
|
cs chunks.ChunkStore
|
||||||
port int
|
port int
|
||||||
l *net.Listener
|
l *net.Listener
|
||||||
conns map[net.Conn]http.ConnState
|
conns map[net.Conn]http.ConnState
|
||||||
writeLimit chan struct{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHttpServer(cs chunks.ChunkStore, port int) *httpServer {
|
func NewHttpServer(cs chunks.ChunkStore, port int) *httpServer {
|
||||||
return &httpServer{
|
return &httpServer{
|
||||||
cs, port, nil, map[net.Conn]http.ConnState{}, make(chan struct{}, maxConcurrentPuts),
|
cs, port, nil, map[net.Conn]http.ConnState{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user