From 8420d77ab50fc9f7f7f75fd48f8d658c1a6ed03f Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Thu, 10 Apr 2014 09:50:30 -0500 Subject: [PATCH] removed ranking from set_bit --- core/service.go | 2 +- index/brand.go | 28 +++++++++++++--------------- index/storage_cass.go | 1 + util/statd.go | 2 ++ 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/core/service.go b/core/service.go index 1be64236c..180d57723 100644 --- a/core/service.go +++ b/core/service.go @@ -48,7 +48,7 @@ func NewService() *Service { service.WebService = NewWebService(service) service.Index = index.NewFragmentContainer() service.Hold = hold.NewHolder() - service.version = "0.0.13" + service.version = "0.0.14" service.name = "Cruncher" service.PrepareLogging() fmt.Printf("Pilosa %s\n", service.version) diff --git a/index/brand.go b/index/brand.go index cc5c51b49..7f644fe96 100644 --- a/index/brand.go +++ b/index/brand.go @@ -37,11 +37,12 @@ type Brand struct { slice int storage Storage rankings RankList - rank_counter int + rank_count int threshold_value uint64 threshold_length int threshold_idx int skip int + rank_time time.Time } func NewBrand(db string, frame string, slice int, s Storage, threshold_len int, threshold int, skipp int) *Brand { @@ -50,7 +51,7 @@ func NewBrand(db string, frame string, slice int, s Storage, threshold_len int, f.frame = frame f.slice = slice f.db = db - f.rank_counter = 0 + f.rank_count = 0 f.threshold_value = 0 f.threshold_length = threshold_len f.threshold_idx = threshold @@ -112,21 +113,12 @@ func (self *Brand) SetBit(bitmap_id uint64, bit_pos uint64, filter uint64) bool self.storage.StoreBlock(int64(bitmap_id), self.db, self.frame, self.slice, filter, int64(address.ChunkKey), int32(address.BlockIndex), int64(val)) self.storage.StoreBlock(int64(bitmap_id), self.db, self.frame, self.slice, filter, COUNTER_KEY, 0, int64(bm.Count())) self.storage.EndBatch() - if bm.Count() >= self.threshold_value { - - self.Rank() //need to optimize this - } + self.rank_count++ } return change } func (self *Brand) Rank() { - if self.rank_counter <= 0 { - self.rank_counter = self.skip - } else { - self.rank_counter -= 1 - return //skip - } start := time.Now() var list RankList for k, item := range self.bitmap_cache { @@ -146,6 +138,7 @@ func (self *Brand) Rank() { //dump(self.rankings, 10) delta := time.Since(start) util.SendTimer("brand_Rank", delta.Nanoseconds()) + self.rank_time = start } @@ -179,7 +172,7 @@ func (self *Brand) Stats() interface{} { "number of bitmaps": len(self.bitmap_cache), "avg size of bitmap in space(bytes)": avg_bytes, "avg size of bitmap in bits": avg_bits, - "rank counter": self.rank_counter, + "rank counter": self.rank_count, "threshold_value": self.threshold_value, "threshold_length": self.threshold_length, "threshold_idx": self.threshold_idx, @@ -192,8 +185,13 @@ func (self *Brand) Store(bitmap_id uint64, bm IBitmap, filter uint64) { } func (self *Brand) TopN(src_bitmap IBitmap, n int, categories []uint64) []Pair { - self.rank_counter = 0 - self.Rank() // TODO: TERRIBLE REMOVE THIS ASAP + if self.rank_count > 0 { + last := time.Since(self.rank_time) * time.Second + if last > 60 { + self.Rank() + } + } + is := NewIntSet() for _, v := range categories { is.Add(v) diff --git a/index/storage_cass.go b/index/storage_cass.go index cca90a2b4..e05597ae1 100644 --- a/index/storage_cass.go +++ b/index/storage_cass.go @@ -123,6 +123,7 @@ func (self *CassandraStorage) EndBatch() { } else { log.Println("NIL BATCH") } + start := time.Now() delta := time.Since(start) util.SendTimer("cassandra_storage_EndBatch", delta.Nanoseconds()) diff --git a/util/statd.go b/util/statd.go index de402db39..debe72370 100644 --- a/util/statd.go +++ b/util/statd.go @@ -22,6 +22,7 @@ func init() { count = make(chan args, 100) end = make(chan bool) stat_config := config.GetStringDefault("statsd_server", "127.0.0.1:8125") + log.Println("New Stats", stat_config) stats, _ := statsd.New(stat_config, "") go func() { for { @@ -44,5 +45,6 @@ func SendTimer(stat string, delta int64) { } func ShutdownStats() { + log.Println("Shutdown Stats") end <- true }