Repository: incubator-htrace Updated Branches: refs/heads/master 021e49144 -> b94898e67
HTRACE-297. htraced: avoid serializing spans to json unless TRACE logging is enabled (cmccabe) Project: http://git-wip-us.apache.org/repos/asf/incubator-htrace/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-htrace/commit/b94898e6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-htrace/tree/b94898e6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-htrace/diff/b94898e6 Branch: refs/heads/master Commit: b94898e67b659acdae78e674775539344598c8ca Parents: 021e491 Author: Colin P. Mccabe <[email protected]> Authored: Thu Nov 12 12:48:14 2015 -0800 Committer: Colin P. Mccabe <[email protected]> Committed: Thu Nov 12 12:52:39 2015 -0800 ---------------------------------------------------------------------- .../src/org/apache/htrace/htraced/datastore.go | 38 +++++++++++++------- .../org/apache/htrace/htraced/datastore_test.go | 19 ++++++---- 2 files changed, 38 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/b94898e6/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go b/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go index c676088..fad69d7 100644 --- a/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go +++ b/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go @@ -134,7 +134,7 @@ func (shd *shard) processIncoming() { err := shd.writeSpan(span) if err != nil { lg.Errorf("Shard processor for %s got fatal error %s.\n", shd.path, err.Error()) - } else { + } else if lg.TraceEnabled() { lg.Tracef("Shard processor for %s wrote span %s.\n", shd.path, span.ToJson()) } case <-shd.heartbeats: @@ -950,9 +950,11 @@ func (pred *predicateData) createSource(store *dataStore, prev *common.Span) (*s // But for some reason someone is asking for another result. // We modify the query to search for the illegal 0 span ID, // which will never be present. - lg.Debugf("Attempted to use a continuation token with an EQUALS "+ - "SPAN_ID query. %s. Setting search id = 0", - pred.Predicate.String()) + if lg.DebugEnabled() { + lg.Debugf("Attempted to use a continuation token with an EQUALS "+ + "SPAN_ID query. %s. Setting search id = 0", + pred.Predicate.String()) + } startId = common.INVALID_SPAN_ID } else { // When doing an EQUALS search on a secondary index, the @@ -1083,8 +1085,10 @@ func (src *source) populateNextFromShard(shardIdx int) { src.numRead[shardIdx]++ key := iter.Key() if !bytes.HasPrefix(key, []byte{src.keyPrefix}) { - lg.Debugf("Can't populate: Iterator for shard %s does not have prefix %s\n", - shdPath, string(src.keyPrefix)) + if lg.DebugEnabled() { + lg.Debugf("Can't populate: Iterator for shard %s does not have prefix %s\n", + shdPath, string(src.keyPrefix)) + } break // Can't read past end of indexed section } var span *common.Span @@ -1094,8 +1098,10 @@ func (src *source) populateNextFromShard(shardIdx int) { sid = common.SpanId(key[1:17]) span, err = src.shards[shardIdx].decodeSpan(sid, iter.Value()) if err != nil { - lg.Debugf("Internal error decoding span %s in shard %s: %s\n", - sid.String(), shdPath, err.Error()) + if lg.DebugEnabled() { + lg.Debugf("Internal error decoding span %s in shard %s: %s\n", + sid.String(), shdPath, err.Error()) + } break } } else { @@ -1103,8 +1109,10 @@ func (src *source) populateNextFromShard(shardIdx int) { sid = common.SpanId(key[9:25]) span = src.shards[shardIdx].FindSpan(sid) if span == nil { - lg.Debugf("Internal error rehydrating span %s in shard %s\n", - sid.String(), shdPath) + if lg.DebugEnabled() { + lg.Debugf("Internal error rehydrating span %s in shard %s\n", + sid.String(), shdPath) + } break } } @@ -1118,8 +1126,10 @@ func (src *source) populateNextFromShard(shardIdx int) { src.nexts[shardIdx] = span // Found valid entry return } else { - lg.Debugf("Span %s from shard %s does not satisfy the predicate.\n", - sid.String(), shdPath) + if lg.DebugEnabled() { + lg.Debugf("Span %s from shard %s does not satisfy the predicate.\n", + sid.String(), shdPath) + } if src.numRead[shardIdx] <= 1 && mayRequireOneSkip(src.pred.Op) { continue } @@ -1200,7 +1210,9 @@ func (store *dataStore) HandleQuery(query *common.Query) ([]*common.Span, error) return nil, err } defer src.Close() - lg.Debugf("HandleQuery %s: preds = %s, src = %v\n", query, preds, src) + if lg.DebugEnabled() { + lg.Debugf("HandleQuery %s: preds = %s, src = %v\n", query, preds, src) + } // Filter the spans through the remaining predicates. ret := make([]*common.Span, 0, 32) http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/b94898e6/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go b/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go index 50d2891..576ee0b 100644 --- a/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go +++ b/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go @@ -352,7 +352,8 @@ func TestQueries4(t *testing.T) { func BenchmarkDatastoreWrites(b *testing.B) { htraceBld := &MiniHTracedBuilder{Name: "BenchmarkDatastoreWrites", Cnf: map[string]string{ - conf.HTRACE_METRICS_HEARTBEAT_PERIOD_MS: "1", + conf.HTRACE_METRICS_HEARTBEAT_PERIOD_MS: "15000", + conf.HTRACE_LOG_LEVEL: "INFO", }, WrittenSpans: make(chan *common.Span, b.N)} ht, err := htraceBld.Build() @@ -362,21 +363,27 @@ func BenchmarkDatastoreWrites(b *testing.B) { defer ht.Close() rnd := rand.New(rand.NewSource(1)) allSpans := make([]*common.Span, b.N) + for n := range(allSpans) { + allSpans[n] = test.NewRandomSpan(rnd, allSpans[0:n]) + } + + // Reset the timer to avoid including the time required to create new + // random spans in the benchmark total. + b.ResetTimer() + // Write many random spans. for n := 0; n < b.N; n++ { - span := test.NewRandomSpan(rnd, allSpans[0:n]) ht.Store.WriteSpan(&IncomingSpan{ - Addr: "127.0.0.1:1234", - Span: span, + Addr: "127.0.0.1", + Span: allSpans[n], }) - allSpans[n] = span } // Wait for all the spans to be written. for n := 0; n < b.N; n++ { <-ht.Store.WrittenSpans } waitForMetrics(ht.Store.msink, common.SpanMetricsMap{ - "127.0.0.1:1234": &common.SpanMetrics{ + "127.0.0.1": &common.SpanMetrics{ Written: uint64(b.N), // should be less than? }, })
