Closed eidheim closed 7 years ago
Currently, I'm doing some tests to see if it is feasible to let users construct Server and Client objects like before (without ::create
that returns a shared_ptr). I think I'm done with the Client code, and if it seems to be ok I'll start on the Server as well. I had to implement shared mutex, read-preferring R/W locking that is, to make this work without too much overhead. Hopefully, we get equally many requests/sec as before from the server. We'll see.
edit: server code is close to done too.
My shared mutex implementation seems more expensive than I thought. I'm getting around 59k req/secs on the v3 branch, and around 63k on master... I'll look at this later and see if there is something that can be done.
@jeffreyscottgraham std::shared_mutex
is c++17 sadly, it didn't even make it to c++14 for some reason. I guess it was a good reason though, but I cannot tell yet, have only studied readers-writer locks for some hours Today. Also, using the boost version is not an alternative, since the header files should work without boost when compiling with standalone asio.
I can't tell if the fair algorithm used in boost/c++17 is faster, I think not actually, since the one I'm using is read-preferring, while the fair algorithm does not have preference. Most likely I have to abandon using shared mutexes because of the overhead. It is a bit sad though, since I'm really happy about how the Client and Server is behaving upon destruction in the v3 branch.
I ran into this related ticket: https://svn.boost.org/trac10/ticket/11798#comment:8. It's been open for a while. I also tested on Linux, which is mentioned to be slow in the issue, since, like I'm doing, "heavyweight" mutexes are used to guard the shared mutex state.
Before I give up, I'll try the platform dependent shared locks (pthread shared locks on unix like systems). Their implementation is sured to be based on atomics and should be much faster.
pthread shared locks are just as slow, so readers-writer locks are out of the question. Back to the drawing board.
This PR is coming along nicely. There are some added complexity, but concerning the readers-writer lock problem, I solved it by not using it when an internal io_service is used (the most common use case). That is, the shared mutex is only needed when the lifetime of the io_service is not known by the server.
There is also the possibility later to write a faster readers-writer lock for our use case, but that will require some research. Extra information if someone is interested in this: the lock should be highly optimised for readers.
Please see #134 for information on the changes.
I'll do a v2 minor release before releasing v3.
Let me know what you think of the changes in this PR. Testing feedback is also welcome!
edit: typo edit2: removed old issues