Skip to content

brpc单个请求延时较高 #2000

@zhouyanghere

Description

@zhouyanghere

Describe the bug (描述bug)
使用redis-benchmark -t set -c 1 -n 100000单链接无压力测试,对比redis server的20+us的单个请求延时,brpc redis server一般达到了40us+

To Reproduce (复现方法)
redis-benchmark -t set -c 1 -n 100000

Expected behavior (期望行为)
较低的延时。

Versions (各种版本)
OS:
Compiler:
brpc:
protobuf:

Additional context/screenshots (更多上下文/截图)
int Socket::StartInputEvent(SocketId id, uint32_t events,
const bthread_attr_t& thread_attr) {
SocketUniquePtr s;
if (Address(id, &s) < 0) {
return -1;
}
if (NULL == s->_on_edge_triggered_events) {
// Callback can be NULL when receiving error epoll events
// (Added into epoll by `WaitConnected')
return 0;
}
if (s->fd() < 0) {
#if defined(OS_LINUX)
CHECK(!(events & EPOLLIN)) << "epoll_events=" << events;
#elif defined(OS_MACOSX)
CHECK((short)events != EVFILT_READ) << "kqueue filter=" << events;
#endif
return -1;
}

// if (events & has_epollrdhup) {
//     s->_eof = 1;
// }
// Passing e[i].events causes complex visibil2ity issues and
// requires stronger memory fences, since reading the fd returns
// error as well, we don't pass the events.
if (s->_nevent.fetch_add(1, butil::memory_order_acq_rel) == 0) {
    // According to the stats, above fetch_add is very effective. In a
    // server processing 1 million requests per second, this counter
    // is just 1500~1700/s
    g_vars->neventthread << 1;

    bthread_t tid;
    // transfer ownership as well, don't use s anymore!
    Socket* const p = s.release();

    bthread_attr_t attr = thread_attr;
    attr.keytable_pool = p->_keytable_pool;

//如果此处注释了if, 不使用bthread 执行task,而是直接执行,则延时直接下降到20us
if (bthread_start_urgent(&tid, &attr, ProcessEvent, p) != 0) {
LOG(FATAL) << "Fail to start ProcessEvent";
ProcessEvent(p);
}
}
return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions