3 ms·
The author very much did try to do that, doing requests with async APIs is often the most performant way to do them because under the hood they use IO async pri
by mpeg 5y ago
The author very much did try to do that, doing requests with async APIs is often the most performant way to do them because under the hood they use IO async primitives like epoll/kqueue/iocp depending on the environment they run on.
If you check the code in the article, there is an innocent looking call to decode the response as JSON; that's most likely where the CPU time is going, most JSON decoders are just not very fast. I remember back in the day having to write my own decoder for a JSON API because I was getting capped on around 250req/s on a windows machine (using c# and iocp which is pretty fast). I think I almost doubled performance by taking some decoding shortcuts when the JSON structure was known ahead of time.
TL;DR: network I/O is fast, json is a really slow format to parse.
- anamax 5y agoJson decoding will show up as CPU usage. Epoll to decide which socket to read is just one thing - efficiently using sockets also matters, hence my suggestion of communication pipelining.