metrics_test.cpp 4.9 KB
Newer Older
Y
yu yunfeng 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*******************************************************************************
 * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 ******************************************************************************/
#include <chrono>
#include <chrono>
#include <map>
#include <memory>
#include <string>
#include <thread>
#include <gtest/gtest.h>
Y
yu yunfeng 已提交
13 14
//#include "prometheus/registry.h"
//#include "prometheus/exposer.h"
Y
yu yunfeng 已提交
15 16
#include <cache/CpuCacheMgr.h>

Y
yu yunfeng 已提交
17
#include "metrics/Metrics.h"
G
groot 已提交
18
#include "utils.h"
Y
yu yunfeng 已提交
19
#include "db/DB.h"
S
starlord 已提交
20
#include "db/meta/SqliteMetaImpl.h"
Y
yu yunfeng 已提交
21 22 23
#include "db/Factories.h"


J
jinhai 已提交
24
using namespace zilliz::milvus;
Y
yu yunfeng 已提交
25 26


G
groot 已提交
27
TEST_F(MetricTest, Metric_Tes) {
Y
yu yunfeng 已提交
28

Y
yu yunfeng 已提交
29
    server::SystemInfo::GetInstance().Init();
Y
yu yunfeng 已提交
30 31
//    server::Metrics::GetInstance().Init();
//    server::Metrics::GetInstance().exposer_ptr()->RegisterCollectable(server::Metrics::GetInstance().registry_ptr());
Y
yu yunfeng 已提交
32
    server::Metrics::GetInstance().Init();
Y
yu yunfeng 已提交
33

Y
yu yunfeng 已提交
34
//    server::PrometheusMetrics::GetInstance().exposer_ptr()->RegisterCollectable(server::PrometheusMetrics::GetInstance().registry_ptr());
Y
yu yunfeng 已提交
35
    zilliz::milvus::cache::CpuCacheMgr::GetInstance()->SetCapacity(1UL*1024*1024*1024);
J
jinhai 已提交
36
    std::cout<<zilliz::milvus::cache::CpuCacheMgr::GetInstance()->CacheCapacity()<<std::endl;
Y
yu yunfeng 已提交
37

J
jinhai 已提交
38
    static const char* group_name = "test_group";
Y
yu yunfeng 已提交
39 40
    static const int group_dim = 256;

41
    engine::meta::TableSchema group_info;
G
groot 已提交
42 43
    group_info.dimension_ = group_dim;
    group_info.table_id_ = group_name;
44 45 46
    engine::Status stat = db_->CreateTable(group_info);

    engine::meta::TableSchema group_info_get;
G
groot 已提交
47
    group_info_get.table_id_ = group_name;
48
    stat = db_->DescribeTable(group_info_get);
Y
yu yunfeng 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75


    engine::IDNumbers vector_ids;
    engine::IDNumbers target_ids;

    int d = 256;
    int nb = 50;
    float *xb = new float[d * nb];
    for(int i = 0; i < nb; i++) {
        for(int j = 0; j < d; j++) xb[d * i + j] = drand48();
        xb[d * i] += i / 2000.;
    }

    int qb = 5;
    float *qxb = new float[d * qb];
    for(int i = 0; i < qb; i++) {
        for(int j = 0; j < d; j++) qxb[d * i + j] = drand48();
        qxb[d * i] += i / 2000.;
    }

    std::thread search([&]() {
        engine::QueryResults results;
        int k = 10;
        std::this_thread::sleep_for(std::chrono::seconds(2));

        INIT_TIMER;
        std::stringstream ss;
G
groot 已提交
76 77
        uint64_t count = 0;
        uint64_t prev_count = 0;
Y
yu yunfeng 已提交
78 79 80

        for (auto j=0; j<10; ++j) {
            ss.str("");
81
            db_->Size(count);
Y
yu yunfeng 已提交
82 83 84
            prev_count = count;

            START_TIMER;
Y
yu yunfeng 已提交
85
//            stat = db_->Query(group_name, k, qb, qxb, results);
Y
yu yunfeng 已提交
86 87
            ss << "Search " << j << " With Size " << (float)(count*group_dim*sizeof(float))/(1024*1024) << " M";

Y
yu yunfeng 已提交
88 89

//            ASSERT_STATS(stat);
Y
yu yunfeng 已提交
90
            for (auto k=0; k<qb; ++k) {
Y
yu yunfeng 已提交
91
//                ASSERT_EQ(results[k][0].first, target_ids[k]);
Y
yu yunfeng 已提交
92 93
                ss.str("");
                ss << "Result [" << k << "]:";
Y
yu yunfeng 已提交
94 95 96 97
//                for (auto result : results[k]) {
//                    ss << result.first << " ";
//                }

Y
yu yunfeng 已提交
98 99 100 101 102 103
            }
            ASSERT_TRUE(count >= prev_count);
            std::this_thread::sleep_for(std::chrono::seconds(1));
        }
    });

Y
yu yunfeng 已提交
104
    int loop = 10000;
Y
yu yunfeng 已提交
105 106 107

    for (auto i=0; i<loop; ++i) {
        if (i==40) {
108
            db_->InsertVectors(group_name, qb, qxb, target_ids);
Y
yu yunfeng 已提交
109 110
            ASSERT_EQ(target_ids.size(), qb);
        } else {
111
            db_->InsertVectors(group_name, nb, xb, vector_ids);
Y
yu yunfeng 已提交
112
        }
Y
yu yunfeng 已提交
113
        std::this_thread::sleep_for(std::chrono::microseconds(2000));
Y
yu yunfeng 已提交
114 115 116 117 118 119 120 121
    }

    search.join();

    delete [] xb;
    delete [] qxb;
};

Y
Yu Kun 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
TEST_F(MetricTest, Collector_Metrics_Test){
    engine::Status status = engine::Status::OK();
    server::CollectInsertMetrics insert_metrics0(0, status);
    status = engine::Status::Error("error");
    server::CollectInsertMetrics insert_metrics1(0, status);

    server::CollectQueryMetrics query_metrics(10);

    server::CollectMergeFilesMetrics merge_metrics();

    server::CollectBuildIndexMetrics build_index_metrics();

    server::CollectExecutionEngineMetrics execution_metrics(10);

    server::CollectSerializeMetrics serialize_metrics(10);

    server::CollectAddMetrics add_metrics(10, 128);

    server::CollectDurationMetrics duration_metrics_raw(engine::meta::TableFileSchema::RAW);
    server::CollectDurationMetrics duration_metrics_index(engine::meta::TableFileSchema::TO_INDEX);
    server::CollectDurationMetrics duration_metrics_delete(engine::meta::TableFileSchema::TO_DELETE);

    server::CollectSearchTaskMetrics search_metrics_raw(engine::meta::TableFileSchema::RAW);
    server::CollectSearchTaskMetrics search_metrics_index(engine::meta::TableFileSchema::TO_INDEX);
    server::CollectSearchTaskMetrics search_metrics_delete(engine::meta::TableFileSchema::TO_DELETE);

    server::MetricCollector metric_collector();
}

Y
yu yunfeng 已提交
151