Check unnecessary usage of msg.Clone()
msiebeneicher opened this issue · 1 comments
msiebeneicher commented
We need to check unnecessary usage of msg.Clone().
Here an example which make no sense with the new clone handling from v0.5.x:
source producer/scribe.go:203
:
// Convert messages to scribe log format
for idx, msg := range messages {
currentMsg := msg.Clone()
category, exists := prod.category[currentMsg.GetStreamID()]
if !exists {
if category, exists = prod.category[core.WildcardStreamID]; !exists {
category = core.StreamRegistry.GetStreamName(currentMsg.GetStreamID())
}
metricName := scribeMetricMessages + category
tgo.Metric.New(metricName)
tgo.Metric.NewRate(metricName, scribeMetricMessagesSec+category, time.Second, 10, 3, true)
prod.category[currentMsg.GetStreamID()] = category
}
logBuffer[idx] = &scribe.LogEntry{
Category: category,
Message: string(currentMsg.GetPayload()),
}
tgo.Metric.Inc(scribeMetricMessages + category)
}
The file producer had the same issue which i'll fix in #173 by providing a new message method GetOrigStreamID
. The main reason for message cloning was often to get the original stream id, which is not necessary anymore and only need resources.
// GetOrigStreamID returns the original/first streamID
func (msg *Message) GetOrigStreamID() MessageStreamID {
return msg.orig.streamID
}
msiebeneicher commented
Added method by 0f71ba3