提交 c42172f3 编写于 作者: 彭勇升 pengys 提交者: wu-sheng

Feature/1032 (#1045)

* 1. Add the performance collection point.
2. Report formatter.

#1032

* Add a new cache implementation by caffeine.

#1032

* Performance optimization:
Make all the loggers class variable to have the static modifier.

* Time stamp format to time bucket performance optimization.

#1032
上级 4607128c
......@@ -77,7 +77,11 @@ public class ApplicationComponentSpanListener implements EntrySpanListener, Exit
@Override
public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId,
String segmentId) {
timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
if (spanDecorator.getStartTimeMinuteTimeBucket() == 0) {
long startTimeMinuteTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
spanDecorator.setStartTimeMinuteTimeBucket(startTimeMinuteTimeBucket);
}
timeBucket = spanDecorator.getStartTimeMinuteTimeBucket();
}
@Override public void build() {
......
......@@ -77,7 +77,11 @@ public class ApplicationMappingSpanListener implements FirstSpanListener, EntryS
@Override
public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId,
String segmentId) {
timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
if (spanDecorator.getStartTimeMinuteTimeBucket() == 0) {
long startTimeMinuteTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
spanDecorator.setStartTimeMinuteTimeBucket(startTimeMinuteTimeBucket);
}
timeBucket = spanDecorator.getStartTimeMinuteTimeBucket();
}
@Override public void build() {
......
......@@ -51,8 +51,13 @@ public class GlobalTraceSpanListener implements FirstSpanListener, GlobalTraceId
@Override
public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId,
String segmentId) {
this.timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
this.segmentId = segmentId;
if (spanDecorator.getStartTimeMinuteTimeBucket() == 0) {
long startTimeMinuteTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
spanDecorator.setStartTimeMinuteTimeBucket(startTimeMinuteTimeBucket);
}
timeBucket = spanDecorator.getStartTimeMinuteTimeBucket();
}
@Override public void parseGlobalTraceId(UniqueId uniqueId) {
......
......@@ -64,7 +64,11 @@ public class InstanceMappingSpanListener implements FirstSpanListener, EntrySpan
@Override
public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId,
String segmentId) {
timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
if (spanDecorator.getStartTimeMinuteTimeBucket() == 0) {
long startTimeMinuteTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
spanDecorator.setStartTimeMinuteTimeBucket(startTimeMinuteTimeBucket);
}
timeBucket = spanDecorator.getStartTimeMinuteTimeBucket();
}
@Override public void build() {
......
......@@ -60,7 +60,11 @@ public class SegmentDurationSpanListener implements EntrySpanListener, ExitSpanL
@Override
public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId,
String segmentId) {
timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(spanDecorator.getStartTime());
if (spanDecorator.getStartTimeMinuteTimeBucket() == 0) {
long startTimeMinuteTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
spanDecorator.setStartTimeMinuteTimeBucket(startTimeMinuteTimeBucket);
}
timeBucket = spanDecorator.getStartTimeMinuteTimeBucket();
SegmentDuration segmentDuration = new SegmentDuration();
segmentDuration.setId(segmentId);
......
......@@ -68,7 +68,11 @@ public class ServiceReferenceMetricSpanListener implements FirstSpanListener, En
@Override
public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId,
String segmentId) {
this.timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
if (spanDecorator.getStartTimeMinuteTimeBucket() == 0) {
long startTimeMinuteTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
spanDecorator.setStartTimeMinuteTimeBucket(startTimeMinuteTimeBucket);
}
timeBucket = spanDecorator.getStartTimeMinuteTimeBucket();
}
@Override
......
......@@ -31,6 +31,7 @@ public class SpanDecorator implements StandardBuilder {
private StandardBuilder standardBuilder;
private SpanObject spanObject;
private SpanObject.Builder spanBuilder;
private long startTimeMinuteTimeBucket = 0;
private final ReferenceDecorator[] referenceDecorators;
public SpanDecorator(SpanObject spanObject, StandardBuilder standardBuilder) {
......@@ -94,6 +95,14 @@ public class SpanDecorator implements StandardBuilder {
}
}
public void setStartTimeMinuteTimeBucket(long startTimeMinuteTimeBucket) {
this.startTimeMinuteTimeBucket = startTimeMinuteTimeBucket;
}
public long getStartTimeMinuteTimeBucket() {
return startTimeMinuteTimeBucket;
}
public long getStartTime() {
if (isOrigin) {
return spanObject.getStartTime();
......
......@@ -153,6 +153,7 @@ public class SegmentParse {
if (spanDecorator.getSpanId() == 0) {
notifyFirstListener(spanDecorator, applicationId, applicationInstanceId, segmentId);
timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
spanDecorator.setStartTimeMinuteTimeBucket(timeBucket);
}
if (SpanType.Exit.equals(spanDecorator.getSpanType())) {
......@@ -193,6 +194,7 @@ public class SegmentParse {
spanListeners.forEach(SpanListener::build);
}
@GraphComputingMetric(name = "/segment/parse/notifyExitListener")
private void notifyExitListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
String segmentId) {
for (SpanListener listener : spanListeners) {
......@@ -202,6 +204,7 @@ public class SegmentParse {
}
}
@GraphComputingMetric(name = "/segment/parse/notifyEntryListener")
private void notifyEntryListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
String segmentId) {
for (SpanListener listener : spanListeners) {
......@@ -211,6 +214,7 @@ public class SegmentParse {
}
}
@GraphComputingMetric(name = "/segment/parse/notifyLocalListener")
private void notifyLocalListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
String segmentId) {
for (SpanListener listener : spanListeners) {
......@@ -220,6 +224,7 @@ public class SegmentParse {
}
}
@GraphComputingMetric(name = "/segment/parse/notifyFirstListener")
private void notifyFirstListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
String segmentId) {
for (SpanListener listener : spanListeners) {
......@@ -229,6 +234,7 @@ public class SegmentParse {
}
}
@GraphComputingMetric(name = "/segment/parse/notifyGlobalsListener")
private void notifyGlobalsListener(UniqueId uniqueId) {
for (SpanListener listener : spanListeners) {
if (listener instanceof GlobalTraceIdsListener) {
......
......@@ -22,6 +22,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
/**
* @author peng-yongsheng
......@@ -29,36 +30,33 @@ import java.util.Date;
public enum TimeBucketUtils {
INSTANCE;
@GraphComputingMetric(name = "/utils/timeBucket/getMinuteTimeBucket")
public long getMinuteTimeBucket(long time) {
SimpleDateFormat minuteDateFormat = new SimpleDateFormat("yyyyMMddHHmm");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
String timeStr = minuteDateFormat.format(calendar.getTime());
return Long.valueOf(timeStr);
long year = calendar.get(Calendar.YEAR);
long month = calendar.get(Calendar.MONTH) + 1;
long day = calendar.get(Calendar.DAY_OF_MONTH);
long hour = calendar.get(Calendar.HOUR_OF_DAY);
long minute = calendar.get(Calendar.MINUTE);
return year * 100000000 + month * 1000000 + day * 10000 + hour * 100 + minute;
}
@GraphComputingMetric(name = "/utils/timeBucket/getSecondTimeBucket")
public long getSecondTimeBucket(long time) {
SimpleDateFormat secondDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
String timeStr = secondDateFormat.format(calendar.getTime());
return Long.valueOf(timeStr);
}
public long getHourTimeBucket(long time) {
SimpleDateFormat hourDateFormat = new SimpleDateFormat("yyyyMMddHH");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
String timeStr = hourDateFormat.format(calendar.getTime()) + "00";
return Long.valueOf(timeStr);
}
long year = calendar.get(Calendar.YEAR);
long month = calendar.get(Calendar.MONTH) + 1;
long day = calendar.get(Calendar.DAY_OF_MONTH);
long hour = calendar.get(Calendar.HOUR_OF_DAY);
long minute = calendar.get(Calendar.MINUTE);
long second = calendar.get(Calendar.SECOND);
public long getDayTimeBucket(long time) {
SimpleDateFormat dayDateFormat = new SimpleDateFormat("yyyyMMdd");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
String timeStr = dayDateFormat.format(calendar.getTime()) + "0000";
return Long.valueOf(timeStr);
return year * 10000000000L + month * 100000000 + day * 1000000 + hour * 10000 + minute * 100 + second;
}
public String formatMinuteTimeBucket(long minuteTimeBucket) throws ParseException {
......
......@@ -18,15 +18,41 @@
package org.apache.skywalking.apm.collector.core.util;
import java.util.TimeZone;
import org.junit.Before;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.junit.Assert;
import org.junit.Test;
/**
* @author wu-sheng
* @author peng-yongsheng
*/
public class TimeBucketUtilsTest {
@Before
public void setup() {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
@Test
public void testGetMinuteTimeBucket() throws ParseException {
SimpleDateFormat minuteDateFormat = new SimpleDateFormat("yyyyMMddHHmm");
long timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(minuteDateFormat.parse("201803010201").getTime());
Assert.assertEquals(201803010201L, timeBucket);
}
@Test
public void testGetSecondTimeBucket() throws ParseException {
SimpleDateFormat minuteDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
long timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(minuteDateFormat.parse("20180301020102").getTime());
Assert.assertEquals(20180301020102L, timeBucket);
}
/**
* Performance tests
* Running with vm option: -javaagent: collector-instrument-agent.jar
*
* @param args
*/
public static void main(String[] args) {
long now = System.currentTimeMillis();
for (int i = 0; i < 500000; i++) {
TimeBucketUtils.INSTANCE.getMinuteTimeBucket(now);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<Configuration status="info">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout charset="UTF-8" pattern="%d - %c -%-4r [%t] %-5p %x - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册