Skip to content

Commit

Permalink
memory revision
Browse files Browse the repository at this point in the history
  • Loading branch information
lezhnev74 committed Jan 18, 2024
1 parent c0d2a7a commit bf7a7da
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (sc *Scanner) Scan(
msgStartPos, msgStartMatchEnd = 0, msgStartMatchEnd-msgStartPos
}
// if buf has no spare space after the workable area - extend the buffer
if bufLen == cap(buf) {
if bufLen == len(buf) {
// respect max buf size
if len(buf) >= sc.maxBufSize {
return xerrors.Errorf("%w: %d bytes (consider increasing the max buffer size)", MaxBufSizeReached, sc.maxBufSize)
Expand Down
81 changes: 38 additions & 43 deletions search/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,50 @@ import (
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"
"heaplog/common"
"heaplog/indexer"
"heaplog/ingest"
"heaplog/scanner"
"heaplog/test"
"heaplog/tokenizer"
"os"
"regexp"
"slices"
"testing"
"time"
)

func TestQueryPerformance(t *testing.T) {

segmentSize := int64(50_000_000)

storage, _, storageRoot := test.PrepareServices(t, segmentSize)
defer os.Remove(storageRoot)

files := map[string]int64{
"/home/dmitry/Code/go/src/heaplog2/local/logs/500Mb.log": 2905976243,
// "/home/dmitry/Code/go/src/heaplog2/local/logs/laravel-2024-01-17.log": 346914816,
}
_, _, err := storage.CheckInFiles(files)
require.NoError(t, err)

messageStartPattern := regexp.MustCompile(`(?m)^\[(\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}\.?(\d{6}([+-]\d\d:\d\d)?)?)]`)
dateLayout := "2006-01-02T15:04:05.000000-07:00"
_scanner := scanner.NewScanner(dateLayout, messageStartPattern, 1_000_000, 50_000_000)

tokenizerFunc := func(input string) []string {
return tokenizer.TokenizeS2(input, 4, 40)
}
_indexer := indexer.NewIndexer(_scanner, tokenizerFunc)

ingestor := ingest.NewIngestor(storage, _indexer, segmentSize, 1)

require.NoError(t, ingestor.Ingest())

// _, unboundTokenizerFunc := test.PrepareTokenizers()
// _selector := NewSegmentSelector(storage, unboundTokenizerFunc, tokenizerFunc)
// querySearch := NewQuerySearch(_selector, _selector.storage, _scanner)
//
// _, c, err := querySearch.NewQuery("error !debug", nil, nil, 100)
// require.NoError(t, err)
// <-c

time.Sleep(5 * time.Second)
}
//
// func TestQueryPerformance(t *testing.T) {
//
// segmentSize := int64(50_000_000)
//
// storage, _, storageRoot := test.PrepareServices(t, segmentSize)
// defer os.Remove(storageRoot)
//
// files := map[string]int64{
// "/home/dmitry/Code/go/src/heaplog2/local/logs/500Mb.log": 2905976243,
// "/home/dmitry/Code/go/src/heaplog2/local/logs/laravel-2024-01-17.log": 346914816,
// }
// _, _, err := storage.CheckInFiles(files)
// require.NoError(t, err)
//
// messageStartPattern := regexp.MustCompile(`(?m)^\[(\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}\.?(\d{6}([+-]\d\d:\d\d)?)?)]`)
// dateLayout := "2006-01-02T15:04:05.000000-07:00"
// _scanner := scanner.NewScanner(dateLayout, messageStartPattern, 1_000_000, 50_000_000)
//
// tokenizerFunc := func(input string) []string {
// return tokenizer.TokenizeS2(input, 4, 40)
// }
// _indexer := indexer.NewIndexer(_scanner, tokenizerFunc)
//
// ingestor := ingest.NewIngestor(storage, _indexer, segmentSize, runtime.NumCPU())
//
// require.NoError(t, ingestor.Ingest())
//
// // _, unboundTokenizerFunc := test.PrepareTokenizers()
// // _selector := NewSegmentSelector(storage, unboundTokenizerFunc, tokenizerFunc)
// // querySearch := NewQuerySearch(_selector, _selector.storage, _scanner)
// //
// // _, c, err := querySearch.NewQuery("error !debug", nil, nil, 100)
// // require.NoError(t, err)
// // <-c
//
// time.Sleep(5 * time.Second)
// }

func TestBuildQuerySuccess(t *testing.T) {
selector, files := ingestFiles(t, 10)
Expand Down
5 changes: 5 additions & 0 deletions ui/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func buildHeaplog(cfg Config) *heaplog.Heaplog {
ingestWorkers := int(cfg.IngestWorkers)
if ingestWorkers == 0 {
ingestWorkers = runtime.NumCPU()
if ingestWorkers > 4 {
// This is to reduce chances of concurrency for resources
// a magick number :)
ingestWorkers = ingestWorkers - 2
}
}

hl, err := heaplog.NewHeaplog(
Expand Down

0 comments on commit bf7a7da

Please sign in to comment.