refactor(tools) add network speed test codes

This commit is contained in:
Shengliang Guan 2022-04-24 13:53:07 +08:00
parent 15ddbe8231
commit 56e90b1258
3 changed files with 37 additions and 21 deletions

View File

@ -174,8 +174,8 @@ static void dmGetServerStatus(SDnode *pDnode, SServerStatusRsp *pStatus) {
void dmProcessNettestReq(SDnode *pDnode, SRpcMsg *pRpc) { void dmProcessNettestReq(SDnode *pDnode, SRpcMsg *pRpc) {
dDebug("net test req is received"); dDebug("net test req is received");
SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = 0}; SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = 0};
rsp.pCont = rpcMallocCont(shell.args.pktLen); rsp.pCont = rpcMallocCont(pRpc->contLen);
rsp.contLen = shell.args.pktLen; rsp.contLen = pRpc->contLen;
rpcSendResponse(&rsp); rpcSendResponse(&rsp);
} }

View File

@ -242,10 +242,11 @@ static void shellInitArgs(int argc, char *argv[]) {
tstrncpy(shell.args.password, TSDB_DEFAULT_PASS, sizeof(shell.args.password)); tstrncpy(shell.args.password, TSDB_DEFAULT_PASS, sizeof(shell.args.password));
} }
shell.args.pktLen = SHELL_DEF_PKG_LEN; SShellArgs *pArgs = &shell.args;
shell.args.pktNum = SHELL_DEF_PKG_NUM; pArgs->user = TSDB_DEFAULT_USER;
shell.args.displayWidth = SHELL_DEFAULT_MAX_BINARY_DISPLAY_WIDTH; pArgs->pktLen = SHELL_DEF_PKG_LEN;
shell.args.user = TSDB_DEFAULT_USER; pArgs->pktNum = SHELL_DEF_PKG_NUM;
pArgs->displayWidth = SHELL_DEFAULT_MAX_BINARY_DISPLAY_WIDTH;
} }
static int32_t shellCheckArgs() { static int32_t shellCheckArgs() {

View File

@ -17,11 +17,12 @@
#include "shellInt.h" #include "shellInt.h"
static void shellWorkAsClient() { static void shellWorkAsClient() {
SRpcInit rpcInit = {0}; SShellArgs *pArgs = &shell.args;
SEpSet epSet = {.inUse = 0, .numOfEps = 1}; SRpcInit rpcInit = {0};
SRpcMsg rpcRsp = {0}; SEpSet epSet = {.inUse = 0, .numOfEps = 1};
void *clientRpc = NULL; SRpcMsg rpcRsp = {0};
char pass[TSDB_PASSWORD_LEN + 1] = {0}; void *clientRpc = NULL;
char pass[TSDB_PASSWORD_LEN + 1] = {0};
taosEncryptPass_c((uint8_t *)("_pwd"), strlen("_pwd"), pass); taosEncryptPass_c((uint8_t *)("_pwd"), strlen("_pwd"), pass);
rpcInit.label = "CHK"; rpcInit.label = "CHK";
@ -39,18 +40,30 @@ static void shellWorkAsClient() {
printf("failed to init net test client since %s\n", terrstr()); printf("failed to init net test client since %s\n", terrstr());
goto _OVER; goto _OVER;
} }
printf("net test client is initialized\n");
tstrncpy(epSet.eps[0].fqdn, shell.args.host, TSDB_FQDN_LEN); if (pArgs->host == NULL) {
epSet.eps[0].port = (uint16_t)shell.args.port; pArgs->host = tsFirst;
}
char fqdn[TSDB_FQDN_LEN] = {0};
tstrncpy(fqdn, pArgs->host, TSDB_FQDN_LEN);
strtok(fqdn, ":");
if (pArgs->port == 0) {
pArgs->port = tsServerPort;
}
printf("net test client is initialized, the server to connect to is %s:%u\n", fqdn, pArgs->port);
tstrncpy(epSet.eps[0].fqdn, pArgs->host, TSDB_FQDN_LEN);
epSet.eps[0].port = (uint16_t)pArgs->port;
int32_t totalSucc = 0; int32_t totalSucc = 0;
uint64_t startTime = taosGetTimestampUs(); uint64_t startTime = taosGetTimestampUs();
for (int32_t i = 0; i < shell.args.pktNum; ++i) { for (int32_t i = 0; i < pArgs->pktNum; ++i) {
SRpcMsg rpcMsg = {.ahandle = (void *)0x9525, .msgType = TDMT_DND_NET_TEST}; SRpcMsg rpcMsg = {.ahandle = (void *)0x9525, .msgType = TDMT_DND_NET_TEST};
rpcMsg.pCont = rpcMallocCont(shell.args.pktLen); rpcMsg.pCont = rpcMallocCont(pArgs->pktLen);
rpcMsg.contLen = shell.args.pktLen; rpcMsg.contLen = pArgs->pktLen;
printf("net test request is sent, size:%d\n", rpcMsg.contLen); printf("net test request is sent, size:%d\n", rpcMsg.contLen);
rpcSendRecv(clientRpc, &epSet, &rpcMsg, &rpcRsp); rpcSendRecv(clientRpc, &epSet, &rpcMsg, &rpcRsp);
@ -65,8 +78,8 @@ static void shellWorkAsClient() {
uint64_t endTime = taosGetTimestampUs(); uint64_t endTime = taosGetTimestampUs();
uint64_t elT = endTime - startTime; uint64_t elT = endTime - startTime;
printf("\ntotal succ:%5d/%d\tcost:%8.2lf ms\tspeed:%8.2lf MB/s\n", totalSucc, shell.args.pktNum, elT / 1000.0, printf("\ntotal succ:%5d/%d\tcost:%8.2lf ms\tspeed:%8.2lf MB/s\n", totalSucc, pArgs->pktNum, elT / 1000.0,
shell.args.pktLen / (elT / 1000000.0) / 1024.0 / 1024.0 * totalSucc); pArgs->pktLen / (elT / 1000000.0) / 1024.0 / 1024.0 * totalSucc);
_OVER: _OVER:
if (clientRpc != NULL) { if (clientRpc != NULL) {
@ -88,8 +101,10 @@ static void shellProcessMsg(void *p, SRpcMsg *pRpc, SEpSet *pEpSet) {
void shellNettestHandler(int32_t signum, void *sigInfo, void *context) { shellExit(); } void shellNettestHandler(int32_t signum, void *sigInfo, void *context) { shellExit(); }
static void shellWorkAsServer() { static void shellWorkAsServer() {
SShellArgs *pArgs = &shell.args;
SRpcInit rpcInit = {0}; SRpcInit rpcInit = {0};
rpcInit.localPort = shell.args.port; rpcInit.localPort = pArgs->port;
rpcInit.label = "CHK"; rpcInit.label = "CHK";
rpcInit.numOfThreads = tsNumOfRpcThreads; rpcInit.numOfThreads = tsNumOfRpcThreads;
rpcInit.cfp = (RpcCfp)shellProcessMsg; rpcInit.cfp = (RpcCfp)shellProcessMsg;
@ -102,7 +117,7 @@ static void shellWorkAsServer() {
printf("failed to init net test server since %s", terrstr()); printf("failed to init net test server since %s", terrstr());
} }
printf("net test server is initialized\n"); printf("net test server is initialized, port:%u\n", pArgs->port);
taosSetSignal(SIGTERM, shellNettestHandler); taosSetSignal(SIGTERM, shellNettestHandler);
while (1) taosMsleep(10); while (1) taosMsleep(10);