multithreading - Bad Fairness with a ReadWriteLock / SharedLock under load -


We are currently developing a multithreaded server application.

In order to optimize the display, we can get a ReadWriteLock lock that has many threads if they want to read only, but only one thread can lock lock.

This lock is used with a list and there is a "reading" operation again on the list

Now this change from simple mutes actually increased performance, but only For a definite concurrency. If there are more threads, which wait for the lock lock, then it is hungry, because before locking an iterator, another intermediator often locks in advance.

Any idea / default approach that is still doing better performance in the list to provide threads that want to change more fair?

The solution is usually if your problem allows for it. MVCC will continue to read an older version, while the author can update and create a new version.

The problem you describe is that the author can stop before waiting for all the readers, it is normal. If you can not make a version of your data, consider reducing the size of the lock. An example of this is in Java internally, it omits to construct 16 locals, so that parts of the map can be locked without locking the whole object.

One last thought is to try to remove ReadWriteLock completely, and use a lock-free algorithm. This can be the most challenging, and can reduce multi-core concurrency.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -