Azure / Azure/azure-cli

'az resource tag' more than a 1000% slower than 'az tag create'

Open
#17,247 1 comment 0 reactions 1 assignee Claimed by @zhoxing-ms View on GitHub
act-identity-squad ARM feature-request
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

## Describe the bug

**Command Name**
`az resource tag`
`az tag create`

## To Reproduce

- Create resource group: `az group create --location westeurope --resource-group 'rg-tag'`
- Create any resource (NSG as an example as it is quick to create): `az network nsg create --name 'nsg-tag' --resource-group 'rg-tag'`
- Time tagging NSG resource using `az resource tag`:

```console
$ time az resource tag \
--tags my-tag=my-value \
--name 'nsg-tag' \
--resource-group 'rg-tag' \
--resource-type 'Microsoft.Network/networkSecurityGroups'

real 0m35,669s
user 0m1,327s
sys 0m0,080s
```

- Time tagging NSG resource using `az tag create`:

```console
$ time az tag create \
--resource-id \
--tags my-tag=my-value

real 0m2,145s
user 0m1,050s
sys 0m0,077s
```

## Expected Behavior

For:

- the documentation for each sub-command being clear that one is faster than the other;
- the reasons why there is a discrepency in speed being made clear in the documentation;
- the average difference being decreased significantly if there aren't any good reasons for one to take more than a 1000% more time.

## Environment Summary

```text
Linux-5.10.19-200.fc33.x86_64-x86_64-with-glibc2.32
Python 3.9.2
Installer: RPM

azure-cli 2.20.0
```

## Additional Context

Found the following related to this:

- it does **not** matter if the tag already exists when using either command;
- `az resource tag` is **always** slower and executes in about 35 seconds every time;
- it does **not** matter if `--is-incremental` is passed to `az resource tag`;
- still executes in about 35 seconds;
- it does **not** seem to matter what type of resource is targeted;
- `az resource tag` is **always** slower and executes in about 35 seconds every time;
- it seemed that `az tag create` always hovered around 2.5 seconds, while `az resource tag` always hovered around 35 seconds of execution time.

I did not use any special profiling tools to drill down into this further, but here is a slightly more complete output using `perf`:

- `az resource tag`:

```console
$ perf stat --null --repeat 10 --table \
az resource tag \
--tags my-tag=my-value \
--name 'nsg-tag' \
--resource-group 'rg-tag' \
--resource-type 'Microsoft.Network/networkSecurityGroups' \
--output none

Performance counter stats for 'az resource tag --tags my-tag=my-value --name nsg-tag --resource-group rg-tag --resource-type Microsoft.Network/networkSecurityGroups --output none' (10 runs):

# Table of individual measurements:
34,544 (+0,450) #
34,782 (+0,688) #
34,777 (+0,683) #
34,500 (+0,406) #
33,458 (-0,636) #
33,904 (-0,190) #
33,887 (-0,208) #
33,502 (-0,592) #
33,752 (-0,342) #
33,834 (-0,260) #

# Final result:
34,094 +- 0,161 seconds time elapsed ( +- 0,47% )
```

- `az tag create`:

```console
$ perf stat --null --repeat 10 --table \
az tag create \
--resource-id \
--tags my-tag=my-value \
--output none

Performance counter stats for 'az tag create --resource-id --tags my-tag=my-value --output none' (10 runs):

# Table of individual measurements:
3,135 (+0,634) #####
2,505 (+0,004) #
2,386 (-0,115) #
2,383 (-0,118) #
2,425 (-0,076) #
2,364 (-0,137) ##
2,421 (-0,080) #
2,619 (+0,118) #
2,844 (+0,343) ###
1,928 (-0,573) ######

# Final result:
2,501 +- 0,101 seconds time elapsed ( +- 4,04% )
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.