macos: polling is slow when there is no io pending
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- c, macos
- Ambito
- operating-systems, performance
Direzione di ricerca
Inizia con l’issue di Node.js collegata, il gist, il confronto tra fork e le sorgenti degli eventi XNU per comprendere il comportamento di kevent64 su macOS e la modifica EV64 proposta. Riproduci il timing con il programma C kqueue incluso, esegui i test esistenti di libuv e confronta i risultati del benchmark; il lavoro è concluso quando esiste un approccio accettato che preserva la funzionalità attuale affrontando al contempo il ritardo del polling senza I/O.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I created an issue for node.js to discuss this after investigating the slowness on macos highlighted in the original tweet by Jarred Sumner.
That issue and the linked gist should have all the relevant info. Just wondering if libuv maintainers (hi @bnoordhuis!) would be interested in or see value in a patch which uses the same technique to allow a fast return from kevent syscall when there is no io pending. The delay without setting this flag is ~12 µs versus ~160 ns with it.
I have made some changes on my fork here which don't change any existing functionality unless you define EV64 explicitly. The actual change when this is defined is only a single line - the rest is just macros to allow switching between the macos specific 64 bit interface and the standard BSD one. If you are interested in taking a PR I can modify this however you see fit - just let me know.
I built this locally and all tests are passing. I also built node.js main against my fork with EV64 defined and can see the huge speedup when running the micro benchmark script - ~2m versus ~80k ticks per second.
The C program here demonstrates the issue using the kqueue api directly.
#include <sys/event.h>
#include <sys/time.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#define NEVENTS 1024
uint64_t hrtime() {
struct timespec t;
if (clock_gettime(CLOCK_MONOTONIC, &t)) return 0;
return (t.tv_sec * (uint64_t) 1e9) + t.tv_nsec;
}
int main () {
struct timespec tspec;
int count = 7000000;
tspec.tv_sec = tspec.tv_nsec = 0;
int fd = kqueue();
assert(fd > 0);
struct kevent64_s events[NEVENTS];
assert(kevent64(fd, NULL, 0, events, NEVENTS, KEVENT_FLAG_IMMEDIATE, &tspec) == 0);
for (int j = 0; j < 5; j++) {
uint64_t start = hrtime();
for (int i = 0; i < count; i++) {
assert(kevent64(fd, NULL, 0, events, NEVENTS, KEVENT_FLAG_IMMEDIATE, &tspec) == 0);
}
uint64_t nanos = hrtime() - start;
float rate = count / ((float)nanos / 1e9);
uint64_t nanos_op = nanos / count;
fprintf(stderr, "rate %.2f nanos_op %llu\n", rate, nanos_op);
}
assert(close(fd) == 0);
fd = kqueue();
assert(fd > 0);
count = 100000;
struct kevent events2[NEVENTS];
assert(kevent(fd, NULL, 0, events2, NEVENTS, &tspec) == 0);
for (int j = 0; j < 5; j++) {
uint64_t start = hrtime();
for (int i = 0; i < count; i++) {
assert(kevent(fd, NULL, 0, events2, NEVENTS, &tspec) == 0);
}
uint64_t nanos = hrtime() - start;
float rate = count / ((float)nanos / 1e9);
uint64_t nanos_op = nanos / count;
fprintf(stderr, "rate %.2f nanos_op %llu\n", rate, nanos_op);
}
assert(close(fd) == 0);
}
$ clang -O3 -o testy test.c
$ ./testy
rate 6108885.00 nanos_op 163
rate 6433474.50 nanos_op 155
rate 6419933.00 nanos_op 155
rate 6443364.50 nanos_op 155
rate 6472013.00 nanos_op 154
rate 82659.79 nanos_op 12097
rate 82687.20 nanos_op 12093
rate 82429.42 nanos_op 12131
rate 82240.56 nanos_op 12159
rate 82661.98 nanos_op 12097
Here are some links to relevant bits of the XNU source.
- https://github.com/apple-oss-distributions/xnu/blob/main/bsd/sys/event.h#L140
- https://github.com/apple-oss-distributions/xnu/blob/main/bsd/kern/kern_event.c#L7992
- https://github.com/apple-oss-distributions/xnu/blob/main/bsd/kern/kern_event.c#L8026
- https://github.com/apple-oss-distributions/xnu/blob/main/bsd/kern/kern_event.c#L8452
- Lingua principale
- C
- Stelle
- 27.4k
- Fork
- 4k
- Merge medio
- 4g 14h
- PR unite (30g)
- 23
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di libuv/libuv
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 1 giorno
-
windows: misleading comments in tty.cForse già presa @LUX-ETVERITAS l’ha presa 3 giorni fa. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
win,pipe: allow pipe name rebinding for server handoverForse già presa @ntdiary l’ha presa 2 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
libuv/libuv#5470 · 3 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
kqueue: write watcher lost after a full 1024-event poll (w->events keeps POLLOUT after EVFILT_WRITE is deleted)Forse già presa @yxshee l’ha presa 6 giorni fa. Apertabug macos
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
deprecation:active impact:breaking-change
Difficoltà 1/5 1-3 ore Idoneità per principianti 80/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Cisco-Talos/clamav#1957 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Read-only client can close a dead pane (remain-on-exit key)Forse già presa @lingyicute l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni