From bae7e7c3e696b5b09cff701d4055fb1ef08e06c7 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Tue, 10 May 2016 21:02:16 +0200 Subject: [PATCH] Made size of hashes LRU cache a parameter set by the webmapper. --- cmd/mtwebmapper/tilesupdater.go | 5 ++++- common/basetilehash.go | 14 +++++++------- common/basetilehash_test.go | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cmd/mtwebmapper/tilesupdater.go b/cmd/mtwebmapper/tilesupdater.go index a4f9d2f..9f5b14e 100644 --- a/cmd/mtwebmapper/tilesupdater.go +++ b/cmd/mtwebmapper/tilesupdater.go @@ -24,6 +24,9 @@ import ( "bitbucket.org/s_l_teichmann/mtsatellite/common" ) +// Number of check sums to keep in memory. +const maxHashedTiles = 256 + type baseTilesUpdates interface { BaseTilesUpdated([]xz) } @@ -177,7 +180,7 @@ func activeChanges(changes []xzc) []xz { func (tu *tileUpdater) doUpdates() { - bth := common.NewBaseTileHash() + bth := common.NewBaseTileHash(maxHashedTiles) baseDir := filepath.Join(tu.mapDir, "8") diff --git a/common/basetilehash.go b/common/basetilehash.go index f27af76..89a8518 100644 --- a/common/basetilehash.go +++ b/common/basetilehash.go @@ -9,8 +9,6 @@ import ( "sync" ) -const btMaxEntries = 256 - type btKey struct { x int y int @@ -24,14 +22,16 @@ type btHashEntry struct { } type BaseTileHash struct { - hashes map[btKey]*btHashEntry - root btHashEntry + hashes map[btKey]*btHashEntry + maxEntries int + root btHashEntry sync.Mutex } -func NewBaseTileHash() *BaseTileHash { +func NewBaseTileHash(maxEntries int) *BaseTileHash { bth := &BaseTileHash{ - hashes: map[btKey]*btHashEntry{}} + hashes: map[btKey]*btHashEntry{}, + maxEntries: maxEntries} bth.root.next = &bth.root bth.root.prev = &bth.root return bth @@ -76,7 +76,7 @@ func (bth *BaseTileHash) Update(x, y int, hash []byte) bool { return false } var entry *btHashEntry - if len(bth.hashes) >= btMaxEntries { + if len(bth.hashes) >= bth.maxEntries { entry = bth.removeLast() } else { entry = new(btHashEntry) diff --git a/common/basetilehash_test.go b/common/basetilehash_test.go index a45f5cf..7aa89c6 100644 --- a/common/basetilehash_test.go +++ b/common/basetilehash_test.go @@ -7,7 +7,7 @@ package common import "testing" func TestBaseTileHash(t *testing.T) { - bth := NewBaseTileHash() + bth := NewBaseTileHash(256) h1 := []byte{1} h2 := []byte{2} for i := 0; i < 600; i++ {