func setup() { flag.Parse() numCPU := runtime.NumCPU() glog.Infoln("NumCPU", numCPU) if envMaxProcs := os.Getenv("GOMAXPROCS"); envMaxProcs == "" { if numCPU > 1 { // Consuming N-1 appears to greatly reduce per-request latency in loaded systems. runtime.GOMAXPROCS(numCPU - 1) } } glog.Infoln("GOMAXPROCS", runtime.GOMAXPROCS(0)) var d db.DB switch *useDB { case "cassandra": d = cassandradb.New() default: glog.Fatalln("Unknown DB:", *useDB) } if err := d.Init(); err != nil { glog.Fatalln("An error occured Initializing the DB: ", err) } handlers.InitializeAndRegister(d) }
// getDataTableRaw returns a db.DataTable with the X-axis as time, all other // columns sorted by name, and no specified row order. func getDataTableRaw(D db.DB, req db.RowRangeRequests) (dTable *db.DataTable, err error) { t2 := time.Now() if len(req.FilteredSources) == 0 { return dTable, errors.New("No sources selected.") } dTable, err = D.ReadRows(req) if err != nil { return nil, err } t1 := time.Now() if len(dTable.ColumnNames) > 0 { originalName := dTable.ColumnNames[0] dTable.ColumnNames[0] = "!" + originalName // Force first column to sort first. dTable.SortDataColumns() dTable.ColumnNames[0] = originalName // Now remove "!" glog.V(2).Infof("PERF: Data column sort time: %v\n", time.Now().Sub(t1)) } t2Delay := time.Now().Sub(t2) glog.V(2).Infof("PERF: DB read time: %v\n", t2Delay) if glog.V(2) && t2Delay.Seconds() > 0 && len(dTable.ColumnNames) > 0 { glog.Infof("PERF: DB row reads/sec: %d\n", int64(float64(len(dTable.Data))/t2Delay.Seconds())) } return dTable, nil }
func readDir(d db.DB, q url.Values, s string) (db.SourceInfoUncomp, error) { returnMetrics := q.Get("returnMetrics") == "1" returnUnits := q.Get("returnUnits") == "1" returnSelectForDefaults := q.Get("returnSelectForDefaults") == "1" defaultsOnly := q.Get("defaultsOnly") == "1" var prefixMatch bool if (len(s) > 0) && (s[len(s)-1:len(s)] == "*") { prefixMatch = true s = s[:len(s)-1] } dirSearchReq := db.DirectorySearchRequest{ Prefix: s, FileRestrict: "", ReturnMetrics: returnMetrics, ReturnUnits: returnUnits, ReturnSelectForDefaults: returnSelectForDefaults, DefaultsOnly: defaultsOnly, DirPrefixMatch: prefixMatch, FilePrefixMatch: false} // Directory only search. sInfo, err := d.ReadDir(dirSearchReq) if err != nil { return db.SourceInfoUncomp{}, err } // File only search. if len(sInfo.Names) == 0 { path, file := common.GetSrcComponents(s) dirSearchReq.Prefix = path dirSearchReq.FileRestrict = file dirSearchReq.DirPrefixMatch = false dirSearchReq.FilePrefixMatch = prefixMatch sInfo, err = d.ReadDir(dirSearchReq) if err != nil { return db.SourceInfoUncomp{}, err } } return sInfo, nil }
func makeRecordJsonContent(d db.DB, b *bytes.Buffer, rawQuery string) (err error) { req, err := requests.MakeRowReq(rawQuery) if err != nil { return err } glog.V(3).Infoln("rowKey", req.Id) t2 := time.Now() returnValue, err := d.ReadRow(req) if err != nil { return err } glog.V(2).Infof("PERF: DB read time: %v\n", time.Now().Sub(t2)) t3 := time.Now() if err := json.NewEncoder(b).Encode(returnValue); err != nil { return err } glog.V(2).Infof("PERF: JSON marshal time: %v\n", time.Now().Sub(t3)) return nil }