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

Multithread #12

Closed
pakipaki2000 opened this issue Mar 7, 2019 · 9 comments
Closed

Multithread #12

pakipaki2000 opened this issue Mar 7, 2019 · 9 comments

Comments

@pakipaki2000
Copy link

pakipaki2000 commented Mar 7, 2019

Hi,

When you lock shf_set_is_lockable, how do you unlock afterward? I don't find the function in test.9.shf.c.

I have a hard time doing some Get into 2 different threads. it always says:
mremap(): 14: Bad address

If i'm retrieving from a single thread, I have no issues.

Thanks again :)

@simonhf
Copy link
Owner

simonhf commented Mar 7, 2019

Hi @pakipaki2000 and thanks for the new and interesting question!

This idea behind making an unlocked version of a database is for the use case where multiple processes do not need to access the database and therefore the performance overhead of unnecessary spin locks at run-time can be avoided.

Unlocking and then locking a database again has not been considered much so far. Which use case can you imagine for doing this? I.e. let's say during 1,000 ms the database is unlocked for 900 ms, and locked for 100 ms... in which use case is this useful? Because normally use case demand performance which is similar across the entire usage period. Looking forward to hearing your ideas and comments.

@pakipaki2000
Copy link
Author

Any kind of multi-thread/multi-process example would be really useful 👍

@pakipaki2000
Copy link
Author

pakipaki2000 commented Mar 7, 2019

I still get the error =0.000000 23199 mremap(): 14: Bad address when i try to get from different threads at same time tho :(

@pakipaki2000
Copy link
Author

pakipaki2000 commented Mar 7, 2019

My needs are quite simple:

process 1) - 16 threads each -> Get, Insert...
process 2) - 16 threads each -> Get, insert...

The 2 processes must do it simultaneously.
How do I do that?

@simonhf
Copy link
Owner

simonhf commented Mar 8, 2019

"Any kind of multi-thread/multi-process example" Both [1] and [2] are tests which are multi-process.

[1] https://github.com/simonhf/sharedhashfile/blob/master/src/test.q.shf.c
[2] https://github.com/simonhf/sharedhashfile/blob/master/src/test.f.shf.c

@pakipaki2000
Copy link
Author

Thanks Simon! Will check-it out. You are super helpful

@simonhf
Copy link
Owner

simonhf commented Mar 8, 2019

"Bad address when i try to get from different threads at same time tho" SHF is designed to be multi-process but not multi-threaded. Having said that, there is no good reason why it shouldn't be multi-threaded, and It may be possible to fix that in the future, but currently only multi-process works, in that it is designed that way with tests to validate that multi-process works.

Speculation on why multi-threaded likely doesn't work in the current source code: There are some global variables which are not stored in shared memory. Since threads share the same address space in a single process then these might conflict and cause the kind of issues you have seen. This sounds like something which would be 'fixable' but which would require some investigation.

process 1) - 16 threads each -> Get, Insert...
process 2) - 16 threads each -> Get, insert...

The 2 processes must do it simultaneously. How do I do that?

Is it possible to have 32 processes with 1 thread instead of 2 processes with 16 threads?

test.f.shf.c [1] is a simple load test example which can use and report on up to 36 processes simultaneously.

Tip: Keep in mind that you do not want to use more processes than you have CPU cores on your box. Why? Because SHF uses spin locks (actually a technology usually used in the kernel and not in user land) which perform badly if process context switching occurs. To avoid process context switching then always have no more processes than there are CPU cores on the box. That way there are no other processes to context switch to.

[1] https://github.com/simonhf/sharedhashfile/blob/master/src/test.f.shf.c

@pakipaki2000
Copy link
Author

Alright, that explains why :)
Thanks, i'll find a workaround.

@pakipaki2000
Copy link
Author

pakipaki2000 commented Mar 8, 2019

"Bad address when i try to get from different threads at same time tho" SHF is designed to be multi-process but not multi-threaded. Having said that, there is no good reason why it shouldn't be multi-threaded, and It may be possible to fix that in the future, but currently only multi-process works, in that it is designed that way with tests to validate that multi-process works.

Speculation on why multi-threaded likely doesn't work in the current source code: There are some global variables which are not stored in shared memory. Since threads share the same address space in a single process then these might conflict and cause the kind of issues you have seen. This sounds like something which would be 'fixable' but which would require some investigation.

process 1) - 16 threads each -> Get, Insert...
process 2) - 16 threads each -> Get, insert...
The 2 processes must do it simultaneously. How do I do that?

Is it possible to have 32 processes with 1 thread instead of 2 processes with 16 threads?

test.f.shf.c [1] is a simple load test example which can use and report on up to 36 processes simultaneously.

Tip: Keep in mind that you do not want to use more processes than you have CPU cores on your box. Why? Because SHF uses spin locks (actually a technology usually used in the kernel and not in user land) which perform badly if process context switching occurs. To avoid process context switching then always have no more processes than there are CPU cores on the box. That way there are no other processes to context switch to.

[1] https://github.com/simonhf/sharedhashfile/blob/master/src/test.f.shf.c

I have a 64 cores machine for those tests.
Thanks for the clarification, very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants