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

Integrate with terraform-client-go for hcl only mode to eliminate terraform binary #381

Merged
merged 4 commits into from
Mar 29, 2023

Conversation

magodo
Copy link
Collaborator

@magodo magodo commented Mar 28, 2023

Integrate with terraform-client-go for hcl only mode to eliminate terraform binary. This improves the performance (quicker speed and lower footprint) of importing.

To use it, users have to explicitly specify a new hidden flag (--tfclient-plugin-path). This flag is hidden since it is not supposed for CLI users to use, but is meant to be used by module users who wants to get the benefit of performance improvement.

Benchmark

Following tests are done on a Dell workstation that has 8 hyperthread cores and 24G RAM. The provider is a locally built, debug, un-stripped one. The commands being run are:

  1. aztfexport rg -n -f -hcl-only --dev-provider aztfy-vmdisk

    (note the --dev-provider makes aztfexport to use a local provider, which also implies to skip any terraform init runs)

  2. aztfexport rg -n -f -hcl-only -tfclient-plugin-path $HOME/go/bin/terraform-provider-azurerm aztfy-vmdisk

    (note the -tfclient-plugin-path implies aztfexport to use terraform-client-go instead of terraform binary, also it implies to using the same local provider)

The scale of the resource group being exported contains a typical VM setup, with a bunch of security rules, which ends up of 30 resources in total.

cgmemtime

Running cgmemtime for 10 times for each of above command:

  1. Old

    Stat:

    • User Time : 45.991888888s
    • System Time : 5.189444444s
    • Wall Time : 34.252444444s
    • Child RSS high: 133.46MB
    • Group Mem high: 1.16GB
  2. New

    Stat:

    • User Time : 1.004333333s
    • System Time : 86ms
    • Wall Time : 19.357777777s
    • Child RSS high: 126.45MB
    • Group Mem high: 159.74MB

…rraform` binary

Integrate with terraform-client-go for hcl only mode to eliminate `terraform` binary. This improves the performance (quicker speed and lower footprint) of importing.

To use it, users have to explicitly specify a new hidden flag (`--tfclient-plugin-go`). This flag is hidden since it is not supposed for CLI users to use, but is meant to be used by module users who wants to get the benefit of performance improvement.
Copy link
Member

@stemaMSFT stemaMSFT left a comment

Choose a reason for hiding this comment

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

LGTM for the most part, my only question is if customers are able to utilize this by default once the PR is merged or not. Would they have to expose the hidden flag? Assuming they have an easy way to utilize the optimizations in this PR I'll approve this.

@magodo
Copy link
Collaborator Author

magodo commented Mar 29, 2023

@stemaMSFT Users can use the hidden flag if they will, though the flag won't show in the help message. The flag is necessary for specifying the path of the provider, otherwise, we don't know where the provider is...

@magodo magodo merged commit b794b08 into Azure:main Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants