Skip to content

multiprocess_safe_cache - #4404

Merged
juj merged 6 commits into
emscripten-core:incomingfrom
juj:multiprocess_safe_cache
Jun 29, 2016
Merged

juj merged 6 commits into
emscripten-core:incomingfrom
juj:multiprocess_safe_cache

Conversation

@juj

@juj juj commented Jun 19, 2016

Copy link
Copy Markdown
Collaborator

Implement a file-based lock mechanism to access the Emscripten cache. Closes #3850. Also fix an issue from earlier commit where at least on Windows, calling pool.terminate / pool.join might not succeed, but instead throws an "Access is denied" exception.

juj added 2 commits June 19, 2016 22:08
…loses emscripten-core#3850. Also fix an issue from earlier commit where at least on Windows, calling pool.terminate / pool.join might not succeed, but instead throws an "Access is denied" exception.
…delete the cache lock file, in the case that a previous forcibly killed process had left it lying around.
Comment thread tools/cache.py Outdated
self.dirname = dirname
self.debug = debug

def reverse_chop(thestring, ending):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name seems surprising? perhaps "try_remove_ending"?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that's a good name.

@kripken

kripken commented Jun 21, 2016

Copy link
Copy Markdown
Member

Do all tests (including and especially sanity) pass?

We should also add a test for this, in sanity - opening two processes that try to build say libc at the same time. What would happen with this lock, one would block until the other is done?

Could we show a warning to the console when blocking on the lock, so that if a problem happens and the locker is stuck or slow, the user knows what's going on? Or maybe the stack trace from control-c would be enough, if there is something useful on the stack.

@juj

juj commented Jun 28, 2016

Copy link
Copy Markdown
Collaborator Author

Seeing some issues in sanity (#4416), but not related to this pull request. Working on the test.

juj added 3 commits June 28, 2016 20:23
…ipten process invokes Emscripten again as a child process, and the parent has the lock, but child also tries to acquire it.
@juj

juj commented Jun 28, 2016

Copy link
Copy Markdown
Collaborator Author

Added a warning print if accessing the lock takes more than 60 seconds. Also added a test other.test_emcc_multiprocess_cache_access to stress this. Ran through other and asm2 suites, which pass.

@kripken

kripken commented Jun 28, 2016

Copy link
Copy Markdown
Member

60 seconds seems like a lot. I think people would assume it hangs and kill it much sooner. However, in EMCC_DEBUG mode we'd have logging shown, if I read this PR right? So I guess that's ok.

But it seems dangerous to wait 60 seconds and stop. How about after 60 seconds we show a warning (not just in debug output), and continue waiting? So if it frees up later it still works. But the user has an error message telling them why the delay, and maybe also saying how to manually kill the lock if necessary.

@juj

juj commented Jun 28, 2016

Copy link
Copy Markdown
Collaborator Author

In debug mode there is a print before attempting to take the lock. The warning is printed after having waited for 60 seconds, but the code doesn't stop at the 60 seconds mark, but keeps waiting by re-attempting to take the lock without any timeout set (line 46, self.filelock.acquire()). So I think the behavior already is like you describe in the last paragraph.

The trouble with choosing a timeout is that building libc and/or any other thing to the cache can easily take more than 60 seconds on a slower computer or a VM, so anything smaller at least doesn't sound safe.

Also, this lock will not change performance or throughput in any way, so with respect to the performance/timing characteristics the behavior should be identical. The only thing this will delay is the 2nd and subsequent processes will not start each to stomp on building libc and other things to the same cache at the same time.

The only thing that I could think of where performance can get degraded is if two independent Emscripten processes wanted to build two completely different things to the cache, say e.g. build 1 wanted to build SDL2, and build 2 wanted to build freetype, although I expect such circumstances would be extremely rare.

@kripken

kripken commented Jun 28, 2016

Copy link
Copy Markdown
Member

Ok, sounds good.

My last concern is the question in the other thread, why we need to catch new windows errors now.

@juj

juj commented Jun 29, 2016

Copy link
Copy Markdown
Collaborator Author

Thanks, merging. I'm hopeful that Windows would go green on the default run mode after this.

@juj
juj merged commit b266a04 into emscripten-core:incoming Jun 29, 2016
@kripken

kripken commented Jun 29, 2016

Copy link
Copy Markdown
Member

Great. Btw, maybe worth posting to the mailing list to ask for people to test this?

@juj

juj commented Jun 29, 2016

Copy link
Copy Markdown
Collaborator Author

Good idea, let me advertise a bit in there.

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

Successfully merging this pull request may close these issues.

We need a multiple-reader single-writer file lock for emscripten_cache.

2 participants