metrics_test.cpp 3.6 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"
Y
yu yunfeng 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#include "../db/utils.h"
#include "db/DB.h"
#include "db/DBMetaImpl.h"
#include "db/Factories.h"


using namespace zilliz::vecwise;



TEST_F(DBTest, Metric_Tes) {


//    server::Metrics::GetInstance().Init();
//    server::Metrics::GetInstance().exposer_ptr()->RegisterCollectable(server::Metrics::GetInstance().registry_ptr());
Y
yu yunfeng 已提交
33
    server::Metrics::GetInstance().Init();
Y
yu yunfeng 已提交
34
//    server::PrometheusMetrics::GetInstance().exposer_ptr()->RegisterCollectable(server::PrometheusMetrics::GetInstance().registry_ptr());
Y
yu yunfeng 已提交
35
    zilliz::vecwise::cache::CpuCacheMgr::GetInstance()->SetCapacity(4*1024*1024*1024);
Y
yu yunfeng 已提交
36 37 38 39
    std::cout<<zilliz::vecwise::cache::CpuCacheMgr::GetInstance()->CacheCapacity()<<std::endl;
    static const std::string group_name = "test_group";
    static const int group_dim = 256;

40
    engine::meta::TableSchema group_info;
Y
yu yunfeng 已提交
41
    group_info.dimension = group_dim;
42 43 44 45 46 47
    group_info.table_id = group_name;
    engine::Status stat = db_->CreateTable(group_info);

    engine::meta::TableSchema group_info_get;
    group_info_get.table_id = group_name;
    stat = db_->DescribeTable(group_info_get);
Y
yu yunfeng 已提交
48 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 76 77 78 79


    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;
        long count = 0;
        long prev_count = -1;

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

            START_TIMER;
84
            stat = db_->Query(group_name, k, qb, qxb, results);
Y
yu yunfeng 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
            ss << "Search " << j << " With Size " << (float)(count*group_dim*sizeof(float))/(1024*1024) << " M";
//            STOP_TIMER(ss.str());

            ASSERT_STATS(stat);
            for (auto k=0; k<qb; ++k) {
                ASSERT_EQ(results[k][0], target_ids[k]);
                ss.str("");
                ss << "Result [" << k << "]:";
                for (auto result : results[k]) {
                    ss << result << " ";
                }
                /* LOG(DEBUG) << ss.str(); */
            }
            ASSERT_TRUE(count >= prev_count);
            std::this_thread::sleep_for(std::chrono::seconds(1));
        }
    });

    int loop = 100000;

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

    search.join();

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