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

Cache does not work with multiple jest workers #82

Open
imjeremyhi opened this issue Jan 7, 2020 · 3 comments
Open

Cache does not work with multiple jest workers #82

imjeremyhi opened this issue Jan 7, 2020 · 3 comments

Comments

@imjeremyhi
Copy link

When using jest with multiple workers the .eslintcache looks like it is being overwritten by every worker. Hence adding the cache option makes no difference to performance.

Happy to try work on a PR to fix the cache overwriting issue but would need some guidance on what kind of approach would be appropriate.
My initial ideas would be:

  1. A separate folder which creates a cache file for every file. This prevents most of the concurrency issues but may lead to a significantly large memory overhead and lots of os reads.
  2. Pass information to all spawned workers of the current run, and then lock the cache writes so each worker correctly appends to the file.
  3. Or alternatively all workers create separate cache files and they get merged together in the end into a single cache file.

Do any of these ideas seem appropriate? In the meantime will do some more digging around the code base.

@SimenB
Copy link
Member

SimenB commented Jan 7, 2020

Not sure how to best deal with this. Neither Jest nor this plugin writes to the cache directly, so maybe it makes sense to fix this in eslint? I'm not sure we can do anything here.

Eslint would need some kind of lock or something similar. write-file-atomic would kinda work, but it'd discard old writes to the cache between its own read and whenever it's able to write. A more generic lock followed read+write might be needed.

Possibly related to eslint/rfcs#4, eslint/rfcs#11 and eslint/rfcs#42


@ljharb @rogeliog thoughts?

@ljharb
Copy link
Collaborator

ljharb commented Jan 8, 2020

eslint isn't designed to be run in more than one process at a time, so i'm not sure if this can really be avoided if it's eslint itself doing the cache writing.

@kirill-konshin
Copy link

kirill-konshin commented Jul 21, 2020

Each worker may receive own cache sub-directory, but then there would be a problem to merge all caches back to one (option 3, basically).

And on subsequent runs single cache has to be provided to workers (probably just copy-paste before run).

The problem with ESLint is that it is synchronous, it only received async APIs in version 7, as mentioned here eslint/eslint#3565, comment eslint/eslint#3565 (comment).

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

4 participants