oceanbase

Форк
0
/
test_net_performance.cpp 
164 строки · 3.5 Кб
1
/**
2
 * Copyright (c) 2021 OceanBase
3
 * OceanBase CE is licensed under Mulan PubL v2.
4
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
5
 * You may obtain a copy of Mulan PubL v2 at:
6
 *          http://license.coscl.org.cn/MulanPubL-2.0
7
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10
 * See the Mulan PubL v2 for more details.
11
 */
12

13
#define USING_LOG_PREFIX SERVER
14
#include "test_net_performance.h"
15

16
#include "omt/all_mock.h"
17
#include "observer/ob_srv_network_frame.h"
18
#include "observer/omt/ob_multi_tenant.h"
19
#include "observer/omt/ob_worker_processor.h"
20

21
using namespace oceanbase::common;
22
using namespace oceanbase::observer;
23
using namespace oceanbase::omt;
24
using namespace oceanbase::obrpc;
25
using namespace oceanbase::unittest;
26

27
static ObGlobalContext gctx;
28

29
int64_t ccnt = 6;
30
int64_t iocnt = 6;
31
int64_t scnt = 6;
32
int64_t msgcnt = 10000;
33

34
int main(int argc, char *argv[])
35
{
36
  int ret = OB_SUCCESS;
37

38
  all_mock_init();
39

40
  if (!parse_arg(argc, argv)) {
41
    return 1;
42
  }
43

44
  static ObSrvNetworkFrame frame(gctx);
45
  if (OB_FAIL(start_frame(frame))) {
46
    LOG_ERROR("start frame fail");
47
  } else {
48
    //frame.wait();
49
  }
50

51
  TestProxy proxy;
52
  frame.get_proxy(proxy);
53

54
  Client c(proxy);
55
  c.set_thread_count((int)ccnt);
56
  c.start();
57
  c.wait();
58

59
  //frame.wait();
60
  return 0;
61
}
62

63
namespace oceanbase
64
{
65
namespace unittest
66
{
67

68
class Processor
69
    : public ObIWorkerProcessor
70
{
71
public:
72
  Processor()
73
  {
74
    ObRpcResultCode rcode;
75
    rcode.serialize(pbuf_, 1024L, pbuf_len_);
76
  }
77

78
  virtual int process(rpc::ObRequest &req)
79
  {
80
    int ret = OB_SUCCESS;
81

82
    const ObRpcPacket &rpacket = reinterpret_cast<const ObRpcPacket&>(req.get_packet());
83

84
    ObRpcPacketCode pcode = rpacket.get_pcode();
85

86
    void *buf = easy_pool_alloc(req.get_request()->ms->pool, sizeof (ObRpcPacket));
87
    ObRpcPacket *packet = new (buf) ObRpcPacket();
88
    packet->set_pcode(pcode);
89
    packet->set_chid(rpacket.get_chid());
90
    packet->set_content(pbuf_, pbuf_len_);
91
    packet->set_session_id(0);
92
    packet->set_trace_id(common::ObCurTraceId::get());
93
    packet->set_resp();
94
    packet->calc_checksum();
95
    req.get_request()->opacket = packet;
96

97
    easy_request_wakeup(req.get_request());
98
    return ret;
99
  };
100

101
private:
102
  char pbuf_[1024];
103
  int64_t pbuf_len_;
104
}; // end of class Processor
105

106
void Client::run(obsys::CThread *thread, void *arg)
107
{
108

109
  UNUSED(arg);
110

111
  int64_t cnt = msgcnt;
112
  while (cnt--) {
113
    proxy_.to(ObAddr(ObAddr::IPV4, "127.0.0.1", 2500))
114
        .by(500)
115
        .test();
116
  }
117
}
118

119
int start_frame(ObSrvNetworkFrame &frame)
120
{
121
  int ret = OB_SUCCESS;
122

123
  static Processor p;
124
  static ObMultiTenant mt(p);
125
  mt.init(ObAddr());
126
  mt.add_tenant(500, (double)scnt / 4, (double)scnt / 4);
127
  mt.start();
128

129
  gctx.config_ = &ObServerConfig::get_instance();
130
  gctx.omt_ = &mt;
131

132
  GCONF.net_thread_count = iocnt;
133

134
  if (OB_FAIL(frame.init())) {
135
    LOG_ERROR("init net frame fail", K(ret));
136
  } else if (OB_FAIL(frame.start())) {
137
    LOG_ERROR("start net frame fail", K(ret));
138
  }
139

140
  return ret;
141
}
142

143
bool parse_arg(int argc, char *argv[])
144
{
145
  int idx = 0;
146
  if (++idx < argc) {
147
    ccnt = strtol(argv[idx], NULL, 10);
148
  }
149
  if (++idx < argc) {
150
    iocnt = strtol(argv[idx], NULL, 10);
151
  }
152
  if (++idx < argc) {
153
    scnt = strtol(argv[idx], NULL, 10);
154
  }
155
  if (++idx < argc) {
156
    msgcnt = strtol(argv[idx], NULL, 10);
157
  }
158

159
  return ccnt > 0 && iocnt > 0 && scnt > 0 && msgcnt > 0;
160
}
161

162

163
} // end of namespace unittest
164
} // end of namespace oceanbase
165

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.