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

fix(sdk): use lockfiles to prevent multiple simulators on the same state directory #6911

Conversation

skyrpex
Copy link
Contributor

@skyrpex skyrpex commented Jul 15, 2024

Uses a lockfile to prevent multiple simulators on the same state directory, which would cause issues. The lockfile is periodically updated in order to check for staleness.

Additionally, adds a --statedir "mystatedir" flag to wing it that allows users changing the simulator state directory.

Fixes #5799.

Copy link

Thanks for opening this pull request! 🎉
Please consult the contributing guidelines for details on how to contribute to this project.
If you need any assistance, don't hesitate to ping the relevant owner over Discord.

Topic Owner
Wing SDK and utility APIs @chriscbr
Wing Console @ainvoner, @skyrpex, @polamoros
JSON, structs, primitives and collections @hasanaburayyan
Platforms and plugins @hasanaburayyan
Frontend resources (website, react, etc) @tsuf239
Language design @chriscbr
VSCode extension and language server @markmcculloh
Compiler architecture, inflights, lifting @yoav-steinberg
Wing Testing Framework @tsuf239
Wing CLI @markmcculloh
Build system, dev environment, releases @markmcculloh
Library Ecosystem @chriscbr
Documentation @hasanaburayyan
SDK test suite @tsuf239
Examples @hasanaburayyan
Wing Playground @eladcon

@monadabot
Copy link
Contributor

monadabot commented Jul 15, 2024

Console preview environment is available at https://wing-console-pr-6911.fly.dev 🚀

Last Updated (UTC) 2024-07-22 11:15

@skyrpex skyrpex changed the title fix(simulator): use lockfiles to prevent multiple simulators on the same state directory fix(sdk): use lockfiles to prevent multiple simulators on the same state directory Jul 15, 2024
@monadabot monadabot added the ⚠️ pr/review-mutation PR has been mutated and will not auto-merge. Clear this label if the changes look good! label Jul 15, 2024
libs/wingsdk/src/simulator/simulator.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/simulator.ts Show resolved Hide resolved
@skyrpex skyrpex requested a review from Chriscbr July 16, 2024 12:42
libs/wingsdk/src/simulator/lockfile.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/simulator.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/lockfile.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/lockfile.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/lockfile.ts Outdated Show resolved Hide resolved
@skyrpex
Copy link
Contributor Author

skyrpex commented Jul 16, 2024

Note to self:

If the lockfile was compromised, we should close the file handle but not remove the lockfile, since it may be owned by another process.

On the other hand, if we use a directory instead of a file, we shouldn't need to close anything.

@skyrpex skyrpex marked this pull request as ready for review July 22, 2024 11:11
@skyrpex skyrpex requested review from ainvoner, polamoros, eladcon and a team as code owners July 22, 2024 11:11
@monadabot
Copy link
Contributor

Benchmarks

Comparison to Baseline ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟥⬜⬜⬜
Benchmark Before After Change
version 58ms±0.78 57ms±0.61 -1ms (-1.92%)⬜
functions_10.test.w -t sim 520ms±6.73 517ms±23.06 -4ms (-0.73%)⬜
functions_10.test.w -t tf-aws 2221ms±23.89 2224ms±23.79 +3ms (+0.14%)⬜
jsii_small.test.w -t sim 380ms±4.11 384ms±3.64 +5ms (+1.23%)⬜
jsii_small.test.w -t tf-aws 623ms±4.9 629ms±3.82 +6ms (+0.92%)⬜
jsii_big.test.w -t sim 2954ms±12.91 2994ms±15.16 +40ms (+1.34%)⬜
jsii_big.test.w -t tf-aws 3167ms±16.39 3204ms±20.26 +37ms (+1.17%)⬜
hello_world.test.w -t sim 408ms±4 413ms±6.91 +5ms (+1.27%)⬜
hello_world.test.w -t tf-aws 1491ms±13.56 1506ms±7.77 +15ms (+1%)⬜
empty.test.w -t sim 364ms±1.64 377ms±5.19 +13ms (+3.7%)🟥
empty.test.w -t tf-aws 611ms±4 620ms±6.02 +10ms (+1.57%)⬜
functions_1.test.w -t sim 401ms±4.35 409ms±3.59 +8ms (+1.92%)⬜
functions_1.test.w -t tf-aws 853ms±4.66 864ms±5.01 +11ms (+1.25%)⬜

⬜ Within 1.5 standard deviations
🟩 Faster, Above 1.5 standard deviations
🟥 Slower, Above 1.5 standard deviations

Benchmarks may vary outside of normal expectations, especially when running in GitHub Actions CI.

Results
name mean min max moe sd
version 57ms 56ms 59ms 1ms 1ms
functions_10.test.w -t sim 517ms 467ms 577ms 23ms 32ms
functions_10.test.w -t tf-aws 2224ms 2178ms 2289ms 24ms 33ms
jsii_small.test.w -t sim 384ms 376ms 394ms 4ms 5ms
jsii_small.test.w -t tf-aws 629ms 621ms 636ms 4ms 5ms
jsii_big.test.w -t sim 2994ms 2956ms 3030ms 15ms 21ms
jsii_big.test.w -t tf-aws 3204ms 3150ms 3243ms 20ms 28ms
hello_world.test.w -t sim 413ms 401ms 435ms 7ms 10ms
hello_world.test.w -t tf-aws 1506ms 1491ms 1526ms 8ms 11ms
empty.test.w -t sim 377ms 364ms 386ms 5ms 7ms
empty.test.w -t tf-aws 620ms 603ms 631ms 6ms 8ms
functions_1.test.w -t sim 409ms 402ms 419ms 4ms 5ms
functions_1.test.w -t tf-aws 864ms 849ms 874ms 5ms 7ms
Last Updated (UTC) 2024-07-22 11:20

@skyrpex skyrpex removed the ⚠️ pr/review-mutation PR has been mutated and will not auto-merge. Clear this label if the changes look good! label Jul 22, 2024
Copy link
Contributor

mergify bot commented Jul 22, 2024

Thanks for contributing, @skyrpex! This PR will now be added to the merge queue, or immediately merged if simulator-use-lockfile-to-prevent-multiple-instances-on-the-same-state-dir is up-to-date with main and the queue is empty.

mergify bot added a commit that referenced this pull request Jul 22, 2024
@mergify mergify bot merged commit 022caad into main Jul 22, 2024
15 checks passed
@mergify mergify bot deleted the simulator-use-lockfile-to-prevent-multiple-instances-on-the-same-state-dir branch July 22, 2024 16:19
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.79.5.

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.

wing it in the same directory uses the same state
4 participants