-
Notifications
You must be signed in to change notification settings - Fork 41
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
What is the status of LibuvSharp? #2
Comments
I am currently working on the documentation and polishing of the API for a release.
The library supports TCP and UDP. As I said, I am currently polishing the API and replacing some bits of the code to make it more 'high performance'. One more thing: I am actively developing this lib, so if you have a problem I will react immediately to all your requests and suggestions. |
Thanks for comments. You've actually won my attention before commenting :) because this lib seems the most compelling libuv wrapper available in .NET. Meanwhile, I took the lib for a spin and I tried running the provided examples and tests. Compiling libuv + LibuvSharp on Linux and Mac against the latest version of Mono was far more easier than compiling libuv on Windows. The challenge was actually producing the dll version of libuv from the sources. Anyway... I've discovered two issues (running on Windows, compiled with standard .NET c# compiler):
|
Yes, as you can see, it is not a one week project - I have been sitting around freenodes #libuv and talking to the main devs for quite a while now.
Well, the Async examples are just there for fun, I will try to work out a better Async API in the future, but in the first release I want to focus on the basics. Furthermore, I will put all examples into the a seperate book repo, because it get's quite tedious to manage all this in one repo. The second issue is more concerning. What windows version are you using and what libuv version have you compiled? How have you compiled it? |
Regarding the crash: I am using Windows 8 and I've compiled libuv from github (latest) with VS 2012. For creating the dll from lib, I've used the following command lines:
I can send you the uv.def file which I've generated with name of the functions from externals in your sourcecode: Sample content from it: LIBRARY UVWRAP |
I've integrated LibuvSharp in my "tcp server" project and I've gave it a try. Unfortunately, the following behavior was observed (on Windows, for now): When running the project in debug mode in IDE, after processing requests for awhile, the IDE pops with the following exception for the line which contains Loop.Default.Run(); A callback was made on a garbage collected delegate of type 'LibuvSharp!LibuvSharp.Handle+callback::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called. When running in release mode, the server stops processing requests after a while (about after the same period as in debug mode) without any exception. I assume the problem is the same but there is no visible alert due to "Release" mode optimizations. Do you have any idea how can I keep the event loop alive? |
What libuv methods are you using? |
It seems like you are using TcpListener and the Listen method? |
Hi Robert. A a side note I'm going to post soon a patch to libuv to support Visual Studio 2012. |
Yes, please, add a sample where you experience that problem. |
I've sent to your email addresses a small console app which reproduces the behaviour. Also, in lib folder you will find my uv.dll file compiled for 64bit. If something is wrong with it, please replace it with one that you know it works well and try to repeat the test. @gigi81: I'll wait for the VS2012 patch in libuv for recompilation. @txdv: As a side note - for my understanding: what is the recommended way to run the loop without blocking the main application thread? Many thanks for looking into it. |
The best thing would have been to make a gist. What windows version are you running? Win8 32bit or 64bit?
What thread are you talking about?
This really depends much more on the thread you are trying to embed into. |
Here is the patch to suppport vs2012: Now you can run: vcbuild release shared |
So LibuvSharp is 3 times slower? You should use a custom byte buffer allocator, currently it copies every piece of received data into a separate byte array. http://www.mono-project.com/Profiler this is how to use the profiler on mono, I will sit down and benchmark it myself now too.
I just wasn't in need for highspeed performance yet, because I used the library for managing sources which had 1-5 events every second and I didn't had too many sources of events. (darn it, I deleted your message by accident, I swear to god, I pressed NO when it asked if I really want to delete that message, damn github) |
Ok, the ByteBufferAllocator is a big issue in this one. The DefaultByteBufferAllocator(I renamed it to CopyingByteBufferAllocator in master) will copy all data from the buffer to a perfectly fitting byte array for every request. This builds up pressure on the GC and is slow (Buffer.Copy every read). I have tested it with another bytebufferallocator which doesn't copy the data to a perfectly fitting byte array and the result is a speed increase (it hits the roof of this machine) in handled reads per second (http://pastebin.com/wa13LSjA). Just remember, that you need to serialize/deal somehow that byte array segment within the Data event block without calling an async methods (like UVStream::Write, UVTimer.Tick, etc...). This bytebufferallocator allows the user to adjust byte buffer creation to the protocol sitting on top of the tcp protocol. I guess another source of speed increase will be to somehow manage the Request objects which are created for every write (but this is only for writing). And please add some code. If you just say something like "it is slower, it doesn't work, etc...", maybe you mean well, but we can't do much with it. |
I've changed my code to use your StaticByteBufferAllocator. While the performance improved (I am now getting around 17500 msg/s instead of 14000), the CPU utilization is still at 100%. I will try to prepare a sample for performance benchmarks (IOCP windows via APM vs libuv). Unfortunately I cannot share my project and the part which does the message processing is quite intricate (it implements a SMS server using a specific binary protocol) and cannot be easily extracted from the project. I am using this project for benchmarking because I can quite easily compare the performance of the same real life code both on Windows and Linux either using libuv or BCL. Also, the client which I am using to do the load testing is an external verified application which runs on a different linux box than server. Running the profiler on my app on Mono/Linux has given me some pretty interesting results: I am sorry: I know that these stats without the actual code don't mean anything for you (as I said, I will try to prepare an eloquent example), but it might give you some hints referring to libuv.
|
How many cpu cores have you got? How many does the IOCP implementation utilize, how many does the libuv implementation utilize on mono/unix? |
Robert, are you sure you are not using some mutex? Like the .net "lock" or some Synchronized data structure. |
FrameData is yielding on each packet framed from tcp stream. This type of processing on socket read (be it BCL's or libuv) is far more CPU friendly due to avoidance of context switches and locking than putting message framing and command processing to run using the appdomain's threadpool (I've done tests in both cases).
When I try to run LibuvSharp.Tests using the dll produced by your build I receive: It seems that function uv_run_once does no longer exist in libuv repo. @txdv The machine has 2 cores (4 logical processors). IOCP is using all 4 logical processors evenly - at least this is what Process Explorer is reporting while running the test. Can you simulate a load test on a more powerful machine as well some time in the future? |
It looks like you are doing a lot of writes. Try to sum up these into bigger writes. |
I am interested in using this library for developing a high performance socket server on Linux. I've already tried using async sockets under mono but their performance is abysmal compared on how the same IOCP socket server runs under Windows with .NET. While mono uses epoll under Linux when available, the actual implementation of async socket operations (SendAsync, ReceiveAsync, etc) is using a threadpool making them quite unusable in high performance scenarios.
I checked the tcp tests source code regarding the possible operations, but I do not have sufficient information to take an informed decision. I am interested mainly in the following topics:
What is the status of this library regarding sockets support? Was it used until now in production applications?
The text was updated successfully, but these errors were encountered: