diff --git a/model/message.go b/model/message.go index 1d62c7c..dd5e5fb 100644 --- a/model/message.go +++ b/model/message.go @@ -30,8 +30,8 @@ type Message struct { Flags uint64 } -// MessageBaseSize is a rough estimate of the base number of bytes the struct uses before strings are populated -const MessageBaseSize = 104 +// MessageBaseSize 2021.06 byte size of an *empty* message json serialized +const MessageBaseSize float64 = 463 func compareSignatures(a []byte, b []byte) bool { if len(a) != len(b) { diff --git a/storage/v0/stream_store.go b/storage/v0/stream_store.go index a3c2da5..22bf385 100644 --- a/storage/v0/stream_store.go +++ b/storage/v0/stream_store.go @@ -114,7 +114,7 @@ func (ss *streamStore) initBuffer() { func (ss *streamStore) updateBuffer(m model.Message) { ss.messages = append(ss.messages, m) - ss.bufferByteCount += (model.MessageBaseSize * 1.5) + len(m.Message) + ss.bufferByteCount += (104 * 1.5) + len(m.Message) } func (ss *streamStore) updateFile() error { diff --git a/storage/v1/stream_store.go b/storage/v1/stream_store.go index a160e23..8801676 100644 --- a/storage/v1/stream_store.go +++ b/storage/v1/stream_store.go @@ -6,14 +6,19 @@ import ( "fmt" "git.openprivacy.ca/openprivacy/log" "io/ioutil" + "math" "os" "path" "sync" ) +// This number is larger that the recommend chunk size of libsodium secretbox by an order of magnitude. +// Since this code is not performance-sensitive (and is unlikely to gain any significant performance benefit from +// cache-efficient chunking) this size isn’t currently a concern. +// TODO: revise and evaluate better storage options after beta” const ( - fileStorePartitions = 16 - bytesPerFile = 15 * 1024 + fileStorePartitions = 128 + bytesPerFile = 128 * 1024 ) // streamStore is a file-backed implementation of StreamStore using an in memory buffer of ~16KB and a rotating set of files @@ -73,7 +78,7 @@ func (ss *streamStore) initBufferFromStorage() error { func (ss *streamStore) updateBuffer(m model.Message) { ss.messages = append(ss.messages, m) - ss.bufferByteCount += (model.MessageBaseSize * 1.5) + len(m.Message) + ss.bufferByteCount += int(math.Ceil(model.MessageBaseSize*1.5)) + len(m.Message) } func (ss *streamStore) updateFile() error {