Commit f658d9eb authored by 彭勇升 pengys's avatar 彭勇升 pengys Committed by 吴晟
Browse files

Simplify the PxxMetrics and ThermodynamicMetrics to improve performance (#3162)

* Feature of database session

* Make it configurable.

* Change the metrics process flow.
before: metrics entrance -> aggregate worker -> remote worker -> trans worker -> minute, hour, day, month persistence worker -> storage
after: metrics entrance -> aggregate worker -> remote worker -> minute persistence worker ->  trans worker -> hour, day, month persistence worker -> storage

* IntKeyLongValueHashMap instead of IntKeyLongValueArray.

* Make the OAP server can't startup.

* Finish

* Rename the method and fixed some test case issues.

* Rename field.

* no message
parent 0cf99802
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -136,8 +136,8 @@ public class AnalysisResult {
                case "long":
                    serializeFields.addLongField(column.getFieldName());
                    break;
                case "IntKeyLongValueArray":
                    serializeFields.addIntLongValuePairelistField(column.getFieldName());
                case "IntKeyLongValueHashMap":
                    serializeFields.addIntKeyLongValueHashMapField(column.getFieldName());
                    break;
                default:
                    throw new IllegalStateException("Unexpected field type [" + type + "] of persistence column [" + column.getFieldName() + "]");
+5 −5
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ public class PersistenceColumns {
    private List<PersistenceField> longFields = new LinkedList<>();
    private List<PersistenceField> doubleFields = new LinkedList<>();
    private List<PersistenceField> intFields = new LinkedList<>();
    private List<PersistenceField> intLongValuePairListFields = new LinkedList<>();
    private List<PersistenceField> intKeyLongValueHashMap = new LinkedList<>();

    public void addStringField(String fieldName) {
        stringFields.add(new PersistenceField(fieldName));
@@ -43,8 +43,8 @@ public class PersistenceColumns {
        intFields.add(new PersistenceField(fieldName));
    }

    public void addIntLongValuePairelistField(String fieldName) {
        intLongValuePairListFields.add(new PersistenceField(fieldName));
    public void addIntKeyLongValueHashMapField(String fieldName) {
        intKeyLongValueHashMap.add(new PersistenceField(fieldName));
    }

    public List<PersistenceField> getStringFields() {
@@ -63,7 +63,7 @@ public class PersistenceColumns {
        return intFields;
    }

    public List<PersistenceField> getIntLongValuePairListFields() {
        return intLongValuePairListFields;
    public List<PersistenceField> getIntKeyLongValueHashMapFields() {
        return intKeyLongValueHashMap;
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -15,13 +15,13 @@ public void deserialize(org.apache.skywalking.oap.server.core.remote.grpc.proto.
        ${field.setter}(remoteData.getDataIntegers(${field?index}));
    </#list>

    <#list serializeFields.intLongValuePairListFields as field>
        setDetailGroup(new org.apache.skywalking.oap.server.core.analysis.metrics.IntKeyLongValueArray(30));
    <#list serializeFields.intKeyLongValueHashMapFields as field>
        setDetailGroup(new org.apache.skywalking.oap.server.core.analysis.metrics.IntKeyLongValueHashMap(30));

        java.util.Iterator iterator = remoteData.getDataIntLongPairListList().iterator();
        while (iterator.hasNext()) {
            org.apache.skywalking.oap.server.core.remote.grpc.proto.IntKeyLongValuePair element = (org.apache.skywalking.oap.server.core.remote.grpc.proto.IntKeyLongValuePair)(iterator.next());
            super.getDetailGroup().add(new org.apache.skywalking.oap.server.core.analysis.metrics.IntKeyLongValue(element.getKey(), element.getValue()));
            super.getDetailGroup().put(new Integer(element.getKey()), new org.apache.skywalking.oap.server.core.analysis.metrics.IntKeyLongValue(element.getKey(), element.getValue()));
        }
    </#list>
}
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -15,8 +15,8 @@ public org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData.Builde
    <#list serializeFields.intFields as field>
        remoteBuilder.addDataIntegers(${field.getter}());
    </#list>
    <#list serializeFields.intLongValuePairListFields as field>
        java.util.Iterator iterator = super.getDetailGroup().iterator();
    <#list serializeFields.intKeyLongValueHashMapFields as field>
        java.util.Iterator iterator = super.getDetailGroup().values().iterator();
        while (iterator.hasNext()) {
            remoteBuilder.addDataIntLongPairList(((org.apache.skywalking.oap.server.core.analysis.metrics.IntKeyLongValue)(iterator.next())).serialize());
        }
+35 −0
Original line number Diff line number Diff line
/*
 * 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.
 */

package org.apache.skywalking.oap.server.core.analysis.metrics;

/**
 * @author peng-yongsheng
 */
public abstract class GroupMetrics extends Metrics {

    protected void combine(IntKeyLongValueHashMap source, IntKeyLongValueHashMap target) {
        source.forEach((key, element) -> {
            IntKeyLongValue existingElement = target.get(key);
            if (existingElement == null) {
                target.put(key, new IntKeyLongValue(key, element.getValue()));
            } else {
                existingElement.addValue(element.getValue());
            }
        });
    }
}
Loading