Re:All Bitcoin private keys are on this website
by theden on Tuesday December 21, 2021 @08:47AM
(#29637317)
I haven't grokked shared memory in python yet to implement it (https://docs.python.org/3/library/multiprocessing.shared_mem...). Apparently there is also a known bug? (https://stackoverflow.com/questions/14124588/shared-memory-i...), but an improvement I'd like to learn and implement. Though the file I have is just over 1GB, so it's not prohibitive yet.
Funny thing is even though it's throwaway code, ensuring everything worked as expected felt really high-stake since a bug would mean a found key would be lost!
Edit: Also not sure if shared memory would be slower in python3 (or if it was, whether it would matter in this use-case), but an interesting thing to profile.
Re:All Bitcoin private keys are on this website
by wyldfire on Tuesday December 21, 2021 @09:17AM
(#29637561)
multiprocessing relies on the OS' fork() to share the memory transparently to the child(ren). The pages containing the memory will refer back to the same physical page until they're written to. This is what grandparent meant by "sharing memory".
multiprocessing also provides a way to access the OS' explicit shared memory usually used as an IPC mechanism.
Re:All Bitcoin private keys are on this website
by uniqueuid on Tuesday December 21, 2021 @09:23AM
(#29637599)
Right, thanks for clearing that up.
multiprocessing's "shared memory" facility is for writable memory.
What I described is extremely handy as you simply move the parsing code up in the script, before your function definition, and "magically" gain memory efficiency.
You're reading the file in every process, this needs mem x N for N processes.
If you first read in the file, create the set, and then use multiprocessing, you will get forked processes sharing the parent's memory, i.e. only need 1 x N the memory.