func main() { startTime := time.Now() flag.Parse() for i := 0; i < flag.NArg(); i++ { g_argList = append(g_argList, flag.Arg(i)) } flagSetup() tok = tokenbucket.New(time.Millisecond*100, 20) Verbose.Printf("arglist %v\n", g_argList) if len(g_argList) < 1 { usage() } go handleQuit() for _, arg := range g_argList { if quitTime { fmt.Printf("Returning from quit signal\n") break } fmt.Printf("loading %s\n", arg) var err error g_nameList, err = LoadSHA256Names(arg) if err != nil { log.Fatalf("Crashed loading %s\n", arg) } /* if len(countFile) > 0 { modGort_CountMatches(countFile) } if len(countFile) > 0 { modSplit_CountMatches(countFile) } */ if len(countFile) > 0 { modPool_CountMatches(countFile) } if len(killFile) > 0 { fmt.Printf("calling mod_KillMatches\n") mod_KillMatches(killFile) } if len(listFile) > 0 { mod_ListMatches(listFile) } } fmt.Printf("# Final summary for all args:\n") fmt.Printf("# Total bytes matched = %s in %d files\n", mdr.CommaFmtInt64(g_totalBytes), g_totalMatches) fmt.Printf("# Deleted %s total bytes in %s files\n", mdr.CommaFmtInt64(g_totalKillBytes), mdr.CommaFmtInt64(g_totalKillCt)) elapsedTime := time.Now().Sub(startTime) //elapsedSeconds := elapsedTime.Seconds() fmt.Printf("# Elapsed run time is %s\n", mdr.HumanTime(elapsedTime)) }
func main() { hist := make(map[int]int) // add rate is 1000 tokens per second, max of 10 tok := tokenbucket.New(time.Millisecond*1, 10) if false { tok.Take(10) // start with empty bucket } fmt.Printf("Fill Rate is %g per second\n", tok.FillRate()) startTime := time.Now() iter := 0 var wg sync.WaitGroup var lok sync.Mutex for i := 0; i < 29; i++ { wg.Add(1) go func(id int) { defer wg.Done() for { //tok.Dump() time.Sleep(tok.Take(1)) //tok.Wait(5) lok.Lock() fmt.Printf("gort[%d] %d \n", id, iter) hist[id]++ iter++ if iter > 10000 { lok.Unlock() break } lok.Unlock() } }(i) } wg.Wait() fmt.Printf("All done in %v\n", time.Now().Sub(startTime)) fmt.Printf("Histogram of goroutine id and hits\n") fmt.Printf("Fair rate limit would imply nearly equal bucket counts\n") for i := 0; i <= 50; i++ { v, exists := hist[i] if exists { fmt.Printf("%d has %d hits\n", i, v) } } }