Skip to content

Commit

Permalink
Add Bytes helper functions and add size to logging
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Mar 26, 2021
1 parent ec5776f commit b94c70a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions das/das.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,12 @@ func Count(pid string) int {
return mongo.Count("das", "merge", spec)
}

// Bytes gets size of records for given DAS query
func Bytes(pid string) int {
spec := bson.M{"qhash": pid, "das.record": 1}
return mongo.Bytes("das", "merge", spec)
}

// GetTimestamp gets initial timestamp of DAS query request
func GetTimestamp(pid string) int64 {
spec := bson.M{"qhash": pid, "das.record": 0}
Expand Down
25 changes: 25 additions & 0 deletions mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,31 @@ func Count(dbname, collname string, spec bson.M) int {
return nrec
}

// Bytes gets number records from MongoDB
func Bytes(dbname, collname string, spec bson.M) int {

// defer function profiler
defer utils.MeasureTime("mongo/Bytes")()

s := _Mongo.Connect()
defer s.Close()
c := s.DB(dbname).C(collname)
var rec DASRecord
err := c.Find(spec).One(&rec)
if err != nil {
log.Printf("ERROR: unable to find record spec=%+v error=%v\n", spec, err)
}
data, err := json.Marshal(rec)
if err != nil {
log.Printf("ERROR: unable to marshl DASRecord error=%v\n", err)
}
// find total number of records
nrec := Count(dbname, collname, spec)

// return total size of all DAS records for given spec
return nrec * len(data)
}

// Remove records from MongoDB
func Remove(dbname, collname string, spec bson.M) {

Expand Down
4 changes: 3 additions & 1 deletion web/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ func processRequest(dasquery dasql.DASQuery, pid string, idx, limit int) map[str
ts := das.TimeStamp(dasquery)
procTime := time.Now().Sub(time.Unix(ts, 0))
nrec := das.Count(pid)
size := das.Bytes(pid)
response["bytes"] = size
response["nresults"] = nrec
response["timestamp"] = das.GetTimestamp(pid)
response["status"] = status
response["pid"] = pid
response["data"] = data
response["procTime"] = procTime
log.Printf("%v pid=%v status=%v nrecords=%d idx=%v limit=%v processing_time=%v\n", dasquery, pid, status, nrec, idx, limit, procTime)
log.Printf("%v pid=%v status=%v nrecords=%d idx=%v limit=%v bytes=%v processing_time=%v\n", dasquery, pid, status, nrec, idx, limit, size, procTime)
} else if das.CheckData(pid) { // data exists in cache but still processing
response["status"] = "processing"
response["pid"] = pid
Expand Down

0 comments on commit b94c70a

Please sign in to comment.