brpc单个请求延时较高
- Lingua principale
- C++
- Stelle
- 17.6k
- Fork
- 4.1k
- Merge medio
- 2g 12h
- PR unite (30g)
- 69
Descrizione
**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;
}
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia da Socket::StartInputEvent e dal punto di ingresso ProcessEvent mostrato nel report. Riproduci il confronto con redis-benchmark -t set -c 1 -n 100000, quindi misura la differenza di latenza tra il percorso bthread e l'elaborazione diretta. Il lavoro è completato quando la latenza di una singola richiesta è ridotta e il comportamento rilevante del benchmark è verificato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- cpp, redis
- Ambito
- backend-api-design, performance
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100