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

feat(sdk): in-place app updates in simulator #5821

Merged
merged 35 commits into from
Mar 12, 2024
Merged

feat(sdk): in-place app updates in simulator #5821

merged 35 commits into from
Mar 12, 2024

Conversation

eladb
Copy link
Contributor

@eladb eladb commented Feb 29, 2024

In order to improve iteration speed when updating an application, introduce a new simulator API to support in-place updates of an app in the simulator.

It is now possible to use simulator.update(simDir) without needing to stop the simulator and start a new instance. This method will analyze the diff between the currently loaded app and the new app defined in simDir and will create/update/delete resources accordingly.

This implies that if a resource was not updated, it won't be restarted across app updates.

The way this works is that when update(simDir) is called, we read the new simulator.json file and analyze the diff between the current resource configuration and the new one to determine which resources were added (exists only in the new config), removed (doesn't exist in the new config), updated (an attribute was changed) or retained (no change). Then, we:

  1. Stop all deleted and updated resources.
  2. Copy the state from all the retained resources (attributes and resolved properties).
  3. Start all new and updated resources.

Modeled dependencies via an execution graph. This allows us to automatically replace any dependent resources and start in topological order.

Until we can deprecate sim.State (waiting for #5882), we sill have an initialization loop which allows late resolution of tokens.

Next step is to update the Wing Console to use this new API when a new version of the app is compiled.

Future improvements

  • Currently all updates are always a replacement (stop and start), but technically we can
    give resources an opportunity to do an in-place update (basically call resource.update()).
  • We can add support for watching the sim directory and automatically
    updating the app inside the simulator. Wow!

Misc

The api.cleanup() method did not wait for the server to close.

Checklist

  • Title matches Winglang's style guide
  • Description explains motivation and solution
  • Tests added (always)
  • Docs updated (only required for features)
  • Added pr/e2e-full label if this feature requires end-to-end testing

By submitting this pull request, I confirm that my contribution is made under the terms of the Wing Cloud Contribution License.

In order to reduce iteration time when updating an application, introduce a new simulator API to support in-place updates of an app in the simulator.

It is now possible to use `simulator.update(simDir)` without needing to stop the simulator and start a new instance. This method will analyze the diff between the currently loaded app and the new app defined in `simDir` and will create/update/delete resources accordingly.

This implies that if a resource was not updated, it won't be restarted across app updates.

As a future improvement, we can add support for watching the sim directory and automatically updating the app inside the simulator. Wow!
@eladb eladb requested a review from a team as a code owner February 29, 2024 17:18
@monadabot
Copy link
Contributor

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

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 @eladb
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 @skorfmann
Wing Playground @eladcon

@eladb eladb requested a review from Chriscbr February 29, 2024 17:27
@monadabot
Copy link
Contributor

monadabot commented Feb 29, 2024

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

Last Updated (UTC) 2024-03-12 16:20

Copy link
Contributor

@skyrpex skyrpex left a comment

Choose a reason for hiding this comment

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

This looks very good! Can't wait to use it.

libs/wingsdk/src/simulator/simulator.ts Outdated Show resolved Hide resolved
@monadabot
Copy link
Contributor

monadabot commented Feb 29, 2024

Benchmarks

Comparison to Baseline ⬜⬜🟩⬜⬜⬜⬜🟥⬜⬜⬜⬜🟥
Benchmark Before After Change
version 64ms±4.78 59ms±0.83 -5ms (-7.95%)⬜
functions_1.test.w -t sim 556ms±29.84 524ms±9.83 -32ms (-5.73%)⬜
functions_1.test.w -t tf-aws 975ms±5.77 948ms±11.38 -27ms (-2.74%)🟩
jsii_small.test.w -t sim 505ms±6.22 499ms±9.84 -6ms (-1.11%)⬜
jsii_small.test.w -t tf-aws 715ms±4.44 724ms±13.61 +10ms (+1.33%)⬜
jsii_big.test.w -t sim 2896ms±15.41 2913ms±13.33 +17ms (+0.59%)⬜
jsii_big.test.w -t tf-aws 3111ms±15.86 3119ms±11.63 +8ms (+0.25%)⬜
hello_world.test.w -t sim 513ms±4.45 529ms±5.69 +15ms (+2.99%)🟥
hello_world.test.w -t tf-aws 1638ms±12.53 1660ms±8.6 +21ms (+1.3%)⬜
empty.test.w -t sim 484ms±5.06 491ms±6.15 +7ms (+1.47%)⬜
empty.test.w -t tf-aws 704ms±5.07 715ms±6.29 +12ms (+1.65%)⬜
functions_10.test.w -t sim 594ms±8.55 608ms±8.35 +14ms (+2.43%)⬜
functions_10.test.w -t tf-aws 2213ms±9.57 2275ms±12.01 +62ms (+2.81%)🟥

⬜ 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 59ms 57ms 61ms 1ms 1ms
functions_1.test.w -t sim 524ms 509ms 548ms 10ms 14ms
functions_1.test.w -t tf-aws 948ms 928ms 986ms 11ms 16ms
jsii_small.test.w -t sim 499ms 484ms 532ms 10ms 14ms
jsii_small.test.w -t tf-aws 724ms 701ms 772ms 14ms 19ms
jsii_big.test.w -t sim 2913ms 2887ms 2951ms 13ms 19ms
jsii_big.test.w -t tf-aws 3119ms 3085ms 3139ms 12ms 16ms
hello_world.test.w -t sim 529ms 516ms 541ms 6ms 8ms
hello_world.test.w -t tf-aws 1660ms 1639ms 1679ms 9ms 12ms
empty.test.w -t sim 491ms 479ms 505ms 6ms 9ms
empty.test.w -t tf-aws 715ms 699ms 728ms 6ms 9ms
functions_10.test.w -t sim 608ms 580ms 620ms 8ms 12ms
functions_10.test.w -t tf-aws 2275ms 2251ms 2305ms 12ms 17ms
Last Updated (UTC) 2024-03-12 16:26

MarkMcCulloh and others added 3 commits February 29, 2024 13:22
Signed-off-by: monada-bot[bot] <monabot@monada.co>
Co-authored-by: Cristian Pallarés <cristianp@wing.cloud>
libs/wingsdk/src/simulator/simulator.ts Outdated Show resolved Hide resolved
libs/wingsdk/test/simulator/simulator.test.ts Show resolved Hide resolved
libs/wingsdk/src/simulator/simulator.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/graph.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/graph.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/graph.ts Outdated Show resolved Hide resolved
libs/wingsdk/test/simulator/simulator.test.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/simulator.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/simulator.ts Show resolved Hide resolved
Co-authored-by: Mark McCulloh <Mark.McCulloh@gmail.com>
libs/wingsdk/src/simulator/simulator.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/simulator.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/simulator.ts Show resolved Hide resolved
Signed-off-by: monada-bot[bot] <monabot@monada.co>
libs/wingsdk/test/simulator/graph.test.ts Show resolved Hide resolved
libs/wingsdk/src/simulator/simulator.ts Outdated Show resolved Hide resolved
libs/wingsdk/test/target-sim/state.test.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/simulator.ts Show resolved Hide resolved
libs/wingsdk/src/simulator/simulator.ts Show resolved Hide resolved
1. remove the parallelism from "start" and replace with a simple recursive depth-first
2. add test
libs/wingsdk/test/simulator/simulator.test.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/simulator/simulator.ts Show resolved Hide resolved
Signed-off-by: monada-bot[bot] <monabot@monada.co>
Copy link
Contributor

mergify bot commented Mar 12, 2024

Thanks for contributing, @eladb! This PR will now be added to the merge queue, or immediately merged if eladb/sim-update is up-to-date with main and the queue is empty.

@mergify mergify bot merged commit 967abe6 into main Mar 12, 2024
15 checks passed
@mergify mergify bot deleted the eladb/sim-update branch March 12, 2024 16:33
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.61.0.

@eladb eladb mentioned this pull request Mar 12, 2024
16 tasks
eladb added a commit that referenced this pull request Mar 12, 2024
Wing Console used `tryGetResource` and expected it to return `undefined` if the node was not found, but #5821 did not respect this contract.

Fixed and added a test.

Fixes #5923
Fixes #5922
mergify bot pushed a commit that referenced this pull request Mar 12, 2024
Wing Console used `tryGetResource` and expected it to return `undefined` if the node was not found, but #5821 did not respect this contract.

Fixed and added a test.

Fixes #5923 Fixes #5922

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [x] Docs updated (only required for features)
- [x] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
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.

None yet

6 participants