7 ms·
Emiller's Balls-Out Guide to Nginx Module Development
- rmk 17y agoThe lxr link to the nginx source code is not working... Where could I find it?
- tdmackey 17y agogoogle.com http://nginx.org/en/download.html http://nginx.org/en/download.html
- _pius 17y agoThe author later wrote a piece on how this guide allowed him to begin making money as an open source contractor: http://www.evanmiller.org/contracting-advice.html http://www.evanmiller.org/contracting-advice.html
- TimothyFitz 17y agoAfter his contracting he worked with me at IMVU; I learned a lot from him. He left IMVU for the University of Chicago Economics PhD program. I can't wait to see what he'll do next.
- oski 17y agoThe final version of the guide is here: http://www.evanmiller.org/nginx-modules-guide.html http://www.evanmiller.org/nginx-modules-guide.html
- phoboslab 17y agoIs this first code snippet, where the HTTP parser checks for "POST" or "COPY" real? It certainly reads like a joke on how not to optimize your code. Also, wouldn't it be faster to check all four characters at once with a 32bit compare? And what about branch prediction of the CPU?
- vier 17y agothat's exactly what it's doing
- ccarpenterg 17y agoWhat is a 'branch prediction of the CPU'?
- alexgartrell 17y agoThe CPU has an instruction cache (it reaches out to memory for the series of instructions and grabs a whole bunch at once to be more efficient). When there's a branch (logically, an if statement, a loop, or a goto, or a switch) it has to make a decision about whether or not it should cache the instructions in the if statement or the instructions following the if statement. Within the linux kernel the macros likely and unlikely are defined so that you can have code of the style if(likely(x > 10)) { /* These instructions, which probably will be executed, * will be cached */ } if(unlikely(ptr == NULL)) { /* These instructions, which probably won't need to be * executed, will not be cached */ }
- viraptor 17y agoI got disappointed at the beginning. Not only folding string checking into a tree of letter by letter checks doesn't buy you performance with 4 letters, but also if you bring that as an example of performance improvement in a server you're just showing your ignorance. Great speed improvement: switch (*((uint32*)m)) { case 0x54534f50: r->method = NGX_HTTP_POST; Does it matter now if I spend `O(no_reqests^2)` time looking for the next connection to serve?
- jared314 17y agoThat snippet appears to be out of date. Version 0.8.34 does something similar to what you suggest. #define ngx_str3Ocmp(m, c0, c1, c2, c3) \ *(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0)
- yosh 17y agoCareful with casting strings to ints like that, it'll break on architectures that require aligned accesses, i.e. if you try to load a uint32, the address of the memory location must be a multiple of 4. x86 happens to be fine with non-aligned access, but many other architectures aren't. If you look at the nginx source, that #define is guarded under NGX_HAVE_NONALIGNED and there is a fallback that does straight byte by byte comparison.
- viraptor 17y ago> fallback that does straight byte by byte comparison That's not even funny anymore... I wonder how many iterations will it take, until they discover that strncmp compiles down to "repz cmpsb" (or equivalent) and you really cannot do better than that with if-s on each character.
- oldgregg 17y agoI like to think I'm a decent programmer. Then I read threads like this. :o) Keep learning...