Repository navigation
picoev, picohttparser: reimplementation in V - #18506
Conversation
|
Can you also refactor the |
| fn json_response() string { | ||
| msg := Message{ | ||
| message: 'Hello, World!' | ||
| message: 'Hello, World!\n' |
There was a problem hiding this comment.
Why add the \n? Imho it is not related to the rewrite, and will make performance comparisons with the older C implementation slightly harder (the size of the response will increase).
|
|
||
| // ev_set sets a new `kevent` with file descriptor `index` | ||
| [inline] | ||
| pub fn (mut pv Picoev) ev_set(index int, operation int, events int) { |
There was a problem hiding this comment.
Would not that method be useful as a pub in the future as well?
There was a problem hiding this comment.
You're right! Don't know why I removed that
|
Any benchmarks available? It would be interesting to see, even if only for intermediate changes. Of course the code can always be optimized later (and the benchmarks could be run twice... once normally, and once with |
|
@JalonSolov I've done quite some testing for fun. Below are some benchmarks using wrk and baton (a go testing tool). For each benchmark I took the best out of 3. SummaryV version is slightly faster with Memory usage is the 1-4mb higher on the new version. Sending connections from multiple threads.I found that Command usedsending requests from 100 concurrent connections for 30 seconds, with goroutines so covering multiple threads.
OldWith prod: Without prod: NewWith prod: Without prod: Sending connections from a single threadSince Picoev is a single threaded application it is fair to also test the performance when connections come from a single thread. Command usedsending requests from 1000 concurrent connections for 30 seconds from a single thread. OldWith prod: NewWith prod: WindowsFor the windows fans: select could only handle 20 concurrent connections much more and the program segfaults. I tried increasing the maximum open file descriptors and turning of defender, but it seems this is "just windows". Multithreaded epollSince epoll and kqueue can be accessed from multiple threads it is easy to add it in Picoev, I made a simple implementation. The program runs on 10 threads: 1 for accepting connections, 8 workers for processing the handlers, 1 for passing the accepted connections to the 8 workers. |
|
Very nice numbers! |
I think if you use taskset on linux for multithreaded version, you could probably get better results, like 10 cpus (also 10 threads) to server and 14 cpus to wrk, for example (for 24 cpus machine). taskset -c 14-23 ./server ... |
|
|
||
| pret.ret = -1 | ||
| return | ||
| return error('error parsing request: no request foud') |
There was a problem hiding this comment.
| return error('error parsing request: no request foud') | |
| return error('error parsing request: no request found') |
| } else { | ||
| pret.ret = -1 | ||
| return unsafe { nil } | ||
| return error('error parsing request: no newline after http version') |
There was a problem hiding this comment.
Perhaps EOL instead of newline, since it should always be carriage return + newline (\r\n)?
There was a problem hiding this comment.
Or just "\r\n" as you use in a later message.
|
@Casper64 is there a performance impact from the last commit fcb5673 ? I am mostly curious, because of this: |
|
@spytheman interestingly the performance difference is very minimal (1-2%) when the request parsing is done inside the However I just did some benchmarking with plain parsing the request and thatβs almost 2 times slower π€―, so I will revert the change. |
|
@Casper64 can it be merged as it is? |
Should the thirdparty dependency be removed in this pr? If no then it can be merged. |
|
Baby steps. I'd say merge this, and do another PR to clean it up, optimize it, or whatever. Can also wait for the Mac kqueue support, etc. |
|
I am merging it, since it is already quite useful on Linux as it is. |
|
@JalonSolov I'll update the pr description, but mac is supported as is freebsd with kqueue. Any other OS apart from linux will use select. |
Reimplement the picoev and picohttpparser module in V.
fix #18291 #7703
This pullrequest aims to reimplement the picoev and picohttpparser module in V. If it's fully written in V it is easier to contribute for others to improve the module. It will also get rid of a third party depency.
Currently the module works on Linux with
epolland on windows withselect.The
selectversion works on all platforms that support select but for now it's exclusive to windows for testing purposes.Usage
Performance
Performance is as fast, if not faster, as with the C implementation
TODO:
picohttparser.Requestin VAnd other optimizations.
Contribution needed
I am working on the
kqueueimplementation, but since I don't own a mac I can't test it on macos π₯²π€ Generated by Copilot at a19651c
This pull request implements a custom Picoev struct and event loop for the picoev library, and improves the Windows compatibility of the picohttpparser library. It refactors the
picoev.vfile and adds themultiplex_linux.vandmultiplex_windows.vfiles for different event loop implementations. It also changes theresponse.vfile to use the C.send function for sending data.π€ Generated by Copilot at a19651c
picoev.vfile to use Picoev struct and methods instead of C.picoev functions and types (link,link,link,link,link,link,link,link,link,link)response.vfile to use C.send function instead of C.write function for Windows compatibility (link)