-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add performance benchmarks to the readme #88
Comments
The performance actually depends on what underlaying implementation of I have no ideas how to make this benchmark fair enough, if you have any share it with me, preferably the code. |
For environment specific libraries like this one, I recommend re-running tests per environment. It would likely require a fairly large text matrix though. For example, for ReactPy we run each part of our code through IOPS tests. The concept is the same, although we focus on network IO which means we need a live web browser. Since 99% percent of users only care about read/write performance, your test result matrix might look something like this: ReadThis test repeatedly reads 5MB of binary data from a file, and measures how many reads occurred within 60 seconds (higher is better).
WriteThis test repeatedly writes 5MB of binary data to a file, and measures how many writes occurred within 60 seconds (higher is better).
Since I probably don't need to show you how to create the test cases themselves, I'll give some top-level tips. I recommend reading/writing binary data in order to minimize variables. Also, you should use import asyncio
async def read_binary_test():
...
async def main():
tasks = [read_test() for _ in range(500)]
await asyncio.gather(*tasks)
if __name__ == "__main__":
asyncio.run(main()) The write test should make sure to store I arbitrarily chose 5MB as a value that gives Python enough "downtime" to actually do something else while IO is being executed. The test cases should be written to stop recording results after 60 seconds has elapsed. |
This would be quite valuable. According to #18 (comment) performance before new implementation was atrocious (i.e. you will be better of having blocking stdlib write/reads most of the time). #18 (comment) looks like a huge improvement have been achieved, but does not compare against stdlib, which is quite crucial. As for which interface need the benchmark the most - even doing it for just for linux would be good enough, since most of the applications in which performance is critical, tend to be hosted on servers, which tend to be Linux-based. I tried rerunning test from the aforementioned comment, but the results look bad. I hope this benchmark is somewhat botched ( I did not try to debug it, just changed it a little to produce table automatically): https://gist.github.com/rooterkyberian/a2c12fc6269c86bcf4e199149eb6b9ec . Results I got:
I left it running more than an hour after last result and still nothing, so it seems like either benchmarking script is broken or aiofile (caio backend) is. |
Thanks for this script. I ran it to test my fix in #93 and here are my results:
It seems to improve the performance quite a bit (and beat aiofiles!) |
Perhaps I'm reading the results wrong, but it looks like the results suggest that using standard lib with |
Okay I am seeing an issue with the testing methodology. Fundamentally, all Python async file frameworks will perform slower for small reads/writes. This is because they add multiple additional layers of stack complexity compared to standard lib. The only real benefit of The tests would need to be modified to read/write something much larger, like a 5MB text file. |
I think you are mostly right @Archmonger. I have been doing some reading on the subject of async file reading on Linux via Python and would like to add to your point. From what I've learnt; The most "accepted/performant/non-blocking" async file I/O subsystems in Linux are the Linux AIO and the (more recent) IO-uring. This package implements an interface for Linux AIO. Both of them are setup around a queue and can service multiple requests at the same time, f.ex. the client can batch multiple requests at once, for different files etc. Setting up such a capable system for a single file read, is an overkill. Furthermore, to add a nice async/await interface for Python (mapping callbacks to futures), considerable amount of Python code is required. Going from a simple open/iterate over file object implemented in C to a multilayered Python code will always be slower. The performance tests in the link above is not comparing the async capabilities equally. The "async *executor*" tests make the full file read async, not each individual read operation like this package does. New tests should be added to run each open() and readline() on a worker thread to have equivalent async granularity. |
Got reminded of this while working on a project, so I decided to create my own tests. Tests source code: https://gist.github.com/Archmonger/5f42613d7f23724f58eb2091a08ded5a Async tests are run with 500 concurrent tasks via Note that 500 concurrent read/write operations is intentionally IO bound due to operating system IO interrupts. Unfortunately, using Windows 11, WindowsProactorEventLoop, NTFS
Windows 11, WindowsSelectorEventLoopPolicy, NTFS
Unraid 6.12.10 (Linux), SelectorEventLoopPolicy, BTRFS
Unraid 6.12.10 (Linux), Uvloop, BTRFS
|
Rewrote my tests to average out 10 iterations, and also added tests for all the combinations of event loops. |
Right now the performance difference between stdlib files,
aiofiles
, andaiofile
is undocumented.There should be at least two benchmarks:
aiofile
during high IO concurrency scenarios.The text was updated successfully, but these errors were encountered: