Skip to content
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

support for "readers-writers paradigm" in m-concurrent.h #39

Closed
mario-tux opened this issue Nov 23, 2018 · 12 comments
Closed

support for "readers-writers paradigm" in m-concurrent.h #39

mario-tux opened this issue Nov 23, 2018 · 12 comments
Assignees

Comments

@mario-tux
Copy link

In order to maximize throughput on such thread-safe containers it would be useful to support also the above paradigm (not necessary ref: https://en.wikipedia.org/wiki/Readers%E2%80%93writers_problem) using locks and condition variables in order to allow multiple concurrent reads against exclusive writes. This can be alternative to the CONCURRENT_DEF macro.

@P-p-H-d
Copy link
Owner

P-p-H-d commented Nov 23, 2018

Which methods do you think shall support such paradigm?
(See https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock for example of such lock).

@mario-tux
Copy link
Author

If you mean, "what priority policies use?", it would depend on the application you are going to implement. Personally I would use the "Read-preferring RW lock" for my application but, again, it depends. I you want to provide a general approach you should implement both (or the three choices). It's up to you.

@P-p-H-d
Copy link
Owner

P-p-H-d commented Nov 24, 2018

Do you plan to use it on complex base type or small one (like int)?

@mario-tux
Copy link
Author

Not really small. Does it change something?

@P-p-H-d
Copy link
Owner

P-p-H-d commented Nov 24, 2018

The mechanism for Read Preference presented in https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock can take up to 3 mutex lock/unlock for one read access. The overall cost seems quite high. So I am unsure if such solution will be faster than the simpler one of using one lock/unlock.

Maybe the solution presented in http://www.cs.unc.edu/~anderson/papers/ecrts09b.pdf which uses 2 atomic add for read will be better (but need more work for the _blocking methods).

@P-p-H-d
Copy link
Owner

P-p-H-d commented Nov 24, 2018

I have pushed in master an implementation (with the 3 locks/unlocks for reading) as CONCURRENT_RP_DEF.
Can you tell me the performance compared with plain CONCURRENT_DEF?

@P-p-H-d P-p-H-d self-assigned this Nov 24, 2018
@P-p-H-d
Copy link
Owner

P-p-H-d commented Nov 25, 2018

I have pushed in master another implementation (based on atomic_add) as CONCURRENT_RP2_DEF.
Could you tell me which one is better?

@mario-tux
Copy link
Author

I was not able to spot a great difference using CONCURRENT_DEF vs CONCURRENT_RP_DEF in my application: there are many other concurrent aspects.
I'm trying to write a small ad-hoc benchmark for this but I got few minors issues (see #40). At the moment I can't spot great difference between CONCURRENT_DEF and CONCURRENT_RP_DEF. On the other side, CONCURRENT_RP2_DEF looks badly slow. If you are interested in the benchmark code I can provide it as long as issue #40 is fixed. Maybe there is something wrong in my bench...

@P-p-H-d
Copy link
Owner

P-p-H-d commented Nov 25, 2018

I am interested in the benchmark code.

@P-p-H-d
Copy link
Owner

P-p-H-d commented Nov 26, 2018

I have updated the bench at https://gist.github.com/P-p-H-d/d517ae44b74096f2cd6ea724cd68211b

  • by using get_copy instead of get_at_copy (get_at_copy will create a new entry if the entry is not found, so it modifies the dictionary and as such uses a write lock)
  • by using rand_get instead of rand (faster)
  • by removing the sleep.

It seems the reads with CONCURRENT_RP are a little bit faster.

I understand why CONCURRENT_RP2 doesn't work but I think I won't fix it and will remove it.

@P-p-H-d
Copy link
Owner

P-p-H-d commented Nov 29, 2018

I have added some basic tests on CONCURRENT_RP_DEF. I don't plan to do anything else on this ticket.

Faster TS_DICT will need dedicated container. It is planned (see ISSUES.org) and I plan to do read without any lock and write with a few CAS. But this is a lot of work of design.

@mario-tux
Copy link
Author

Thank you. I will test it again.

@P-p-H-d P-p-H-d closed this as completed Dec 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants