未验证 提交 b18424d2 编写于 作者: 夏克 提交者: GitHub

fix issue 'client_performance_test' failed (#80)

* stage线程分配问题 #75
* 客户端连接可以指定host和port
上级 cf468822
......@@ -107,9 +107,6 @@ unsigned int Threadpool::add_threads(unsigned int threads)
LOG_WARN("Failed to create one thread\n");
break;
}
char tmp[16] = {};
snprintf(tmp,sizeof(tmp), "%s%u",name_.c_str(), i);
pthread_setname_np(pthread, tmp);
}
nthreads_ += i;
MUTEX_UNLOCK(&thread_mutex_);
......@@ -259,6 +256,11 @@ void *Threadpool::run_thread(void *pool_ptr)
// this is not portable, but is easier to map to LWP
s64_t threadid = gettid();
LOG_INFO("threadid = %llx, threadname = %s\n", threadid, pool->get_name().c_str());
#ifdef __APPLE__
pthread_setname_np(pool->get_name().c_str());
#else
pthread_setname_np(pthread_self(), pool->get_name().c_str());
#endif
// enter a loop where we continuously look for events from Stages on
// the run_queue_ and handle the event.
......
......@@ -296,7 +296,11 @@ bool TimerStage::initialize()
if (status != 0)
LOG_ERROR("failed to create timer thread: status=%d\n", status);
else
#ifdef __APPLE__
pthread_setname_np("TimerStage");
#else
pthread_setname_np(timer_thread_id_, "TimerStage");
#endif
return (status == 0);
}
......
......@@ -30,10 +30,11 @@ See the Mulan PSL v2 for more details. */
#include "common/metrics/console_reporter.h"
#define MAX_MEM_BUFFER_SIZE 8192
#define PORT_DEFAULT 66789
#define PORT_DEFAULT 6789
using namespace common;
char *server_host = (char *)LOCAL_HOST;
int server_port = PORT_DEFAULT;
void *test_server(void *param)
{
......@@ -60,7 +61,7 @@ void *test_server(void *param)
}
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons((uint16_t)PORT_DEFAULT);
serv_addr.sin_port = htons((uint16_t)server_port);
serv_addr.sin_addr = *((struct in_addr *)host->h_addr);
bzero(&(serv_addr.sin_zero), 8);
......@@ -95,9 +96,17 @@ void *test_server(void *param)
int main(int argc, char *argv[])
{
if (argc >= 2) {
server_host = argv[1];
int opt;
extern char *optarg;
while ((opt = getopt(argc, argv, "h:p:")) > 0) {
switch (opt) {
case 'p':
server_port = atoi(optarg);
break;
case 'h':
server_host = optarg;
break;
}
}
MetricsRegistry &metric_registry = get_metrics_registry();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册