Skip to content

Commit

Permalink
Making sqlite faster. Use int over text and fix retries for bulkupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
faustocarva committed Dec 20, 2023
1 parent b36ebd7 commit d28a324
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 49 deletions.
7 changes: 7 additions & 0 deletions data/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ func NewConnection(cfg *config.Config, logger *zap.Logger) (*connection, error)
return nil, err
}

db.Exec("PRAGMA journal_mode=WAL;")

db.Exec("pragma page_size = 32768;")
db.Exec("pragma mmap_size = 30000000000;")
db.Exec("pragma temp_store = memory;")
db.Exec("pragma synchronous = normal;")

return &connection{
db: db,
databaseName: cfg.DatabaseName,
Expand Down
Binary file added dogefuzz.db-shm
Binary file not shown.
Binary file added dogefuzz.db-wal
Binary file not shown.
8 changes: 4 additions & 4 deletions entities/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ type Transaction struct {
Inputs string `gorm:"not null"`
DetectedWeaknesses string
ExecutedInstructions string
DeltaCoverage string
DeltaMinDistance string
Coverage string
CriticalInstructionsHits string
DeltaCoverage uint64
DeltaMinDistance uint64
Coverage uint64
CriticalInstructionsHits uint64
Status common.TransactionStatus `gorm:"not null"`
}
16 changes: 8 additions & 8 deletions listener/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,18 @@ func (l *fuzzerListener) processEvent(ctx context.Context, evt bus.TaskInputRequ
transaction.Status = common.TRANSACTION_RUNNING
}

tries := 0
for tries <= 5 {
err = l.transactionService.BulkUpdate(transactions)
if err != nil {
time.Sleep(500 * time.Millisecond)
maxRetries := 5
var bulk_error error
for retries := 0; retries < maxRetries; retries++ {
bulk_error = l.transactionService.BulkUpdate(transactions)
if bulk_error != nil {
time.Sleep(100 * time.Millisecond)
continue
} else {
break
}
tries++
}

if err != nil {
if bulk_error != nil {
l.logger.Sugar().Errorf("an error ocurred when updating transactions in database: %v", err)
return
}
Expand Down
45 changes: 8 additions & 37 deletions pkg/mapper/transaction.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mapper

import (
"strconv"
"strings"

"github.com/dogefuzz/dogefuzz/entities"
Expand All @@ -25,10 +24,10 @@ func (m *transactionMapper) MapNewDTOToEntity(n *dto.NewTransactionDTO) *entitie
}

func (m *transactionMapper) MapDTOToEntity(c *dto.TransactionDTO) *entities.Transaction {
coverage := strconv.FormatUint(c.Coverage, 10)
deltaCoverage := strconv.FormatUint(c.DeltaCoverage, 10)
deltaMinDistance := strconv.FormatUint(c.DeltaMinDistance, 10)
criticalInstructionsHits := strconv.FormatUint(c.CriticalInstructionsHits, 10)
coverage := c.Coverage
deltaCoverage := c.DeltaCoverage
deltaMinDistance := c.DeltaMinDistance
criticalInstructionsHits := c.CriticalInstructionsHits

return &entities.Transaction{
Id: c.Id,
Expand Down Expand Up @@ -63,41 +62,13 @@ func (m *transactionMapper) MapEntityToDTO(c *entities.Transaction) *dto.Transac
executedInstructions = strings.Split(c.ExecutedInstructions, ";")
}

var coverage uint64
if c.Coverage != "" {
val, err := strconv.ParseUint(c.Coverage, 10, 64)
if err != nil {
panic(err)
}
coverage = val
}
var coverage uint64 = c.Coverage

var deltaCoverage uint64
if c.DeltaCoverage != "" {
val, err := strconv.ParseUint(c.DeltaCoverage, 10, 64)
if err != nil {
panic(err)
}
deltaCoverage = val
}
var deltaCoverage uint64 = c.DeltaCoverage

var deltaMinDistance uint64
if c.DeltaMinDistance != "" {
val, err := strconv.ParseUint(c.DeltaMinDistance, 10, 64)
if err != nil {
panic(err)
}
deltaMinDistance = val
}
var deltaMinDistance uint64 = c.DeltaMinDistance

var criticalInstructionsHits uint64
if c.CriticalInstructionsHits != "" {
val, err := strconv.ParseUint(c.CriticalInstructionsHits, 10, 64)
if err != nil {
panic(err)
}
criticalInstructionsHits = val
}
var criticalInstructionsHits uint64 = c.CriticalInstructionsHits

return &dto.TransactionDTO{
Id: c.Id,
Expand Down

0 comments on commit d28a324

Please sign in to comment.