nova/nova
Andrey Volkov fa275544c2 AZ list performance optimization: avoid double service list DB fetch
Assume number of services can be large (10000 as in the bug description),
this patch removes second service_get_all call.

zone_hosts changed from dict of lists to dict of sets.

The HostAPI instance from the API controller is also passed to the
get_availability_zones method so it does not have to recreate it
per call (this is both for a slight performance gain but mostly also
for test sanity).

On devstack with 10000 services patch decreased response time twice.

openstack availability zone list --long --timing

...

Before:

+-------------------------------------------------------------------------------------------+-----------+
| URL                                                                                       |   Seconds |
+-------------------------------------------------------------------------------------------+-----------+
| GET http://192.168.0.45/identity                                                          |  0.006816 |
| POST http://192.168.0.45/identity/v3/auth/tokens                                          |  0.456708 |
| POST http://192.168.0.45/identity/v3/auth/tokens                                          |  0.087485 |
| GET http://172.18.237.203/compute/v2.1/os-availability-zone/detail                        | 95.667192 |
| GET http://172.18.237.203/volume/v2/e2671d37ee2c4374bd1533645261f1d4/os-availability-zone |  0.036528 |
| Total                                                                                     | 96.254729 |
+-------------------------------------------------------------------------------------------+-----------+

After:

+-------------------------------------------------------------------------------------------+-----------+
| URL                                                                                       |   Seconds |
+-------------------------------------------------------------------------------------------+-----------+
| GET http://192.168.0.45/identity                                                          |  0.020215 |
| POST http://192.168.0.45/identity/v3/auth/tokens                                          |  0.102987 |
| POST http://192.168.0.45/identity/v3/auth/tokens                                          |  0.111899 |
| GET http://172.18.237.203/compute/v2.1/os-availability-zone/detail                        | 39.346657 |
| GET http://172.18.237.203/volume/v2/e2671d37ee2c4374bd1533645261f1d4/os-availability-zone |  0.026403 |
| Total                                                                                     | 39.608161 |
+-------------------------------------------------------------------------------------------+-----------+

The test_availability_zone_detail unit test is updated to assert that
services are only retrieved twice (once for enabled, once for disabled).
While in there, the expected response dict is formatted for readability
and a duplicate zone/host is added to make sure duplicates are handled
for available services. To ensure service_get_all is called only twice,
the low-level DB API service_get_all stub is replaced with a mock and
the mock is changed to be on the HostAPI.service_get_all method which
is (1) what the API controller code is actually using and (2) allows the
test to only mock the instance of the HostAPI being tested - trying to
mock the DB API service_get_all method causes intermittent failures
in unrelated tests because of the global nature of that mock.

There is another opportunity for optimizing get_availability_zones which
is marked with a TODO but left for a separate patch.

Co-Authored-By: Matt Riedemann <mriedem.os@gmail.com>

Partial-Bug: #1801897
Change-Id: Ib9a9a9a79499272d740a64cc0b909f0299a237d1
(cherry picked from commit 74cefe4266)
(cherry picked from commit c280d747fb)
2019-04-30 13:17:04 +00:00
..
api AZ list performance optimization: avoid double service list DB fetch 2019-04-30 13:17:04 +00:00
cells Add instance action record for snapshot instances 2017-12-11 17:46:38 +08:00
cmd Handle templated cell mappings in nova-status 2019-03-11 21:01:08 -04:00
common
compute Create request spec, build request and mappings in one transaction 2019-04-28 00:42:15 +00:00
conductor Merge "Fix incomplete instance data returned after build failure" into stable/rocky 2019-04-17 20:29:39 +00:00
conf libvirt: Add workaround to cleanup instance dir when using rbd 2019-01-15 15:53:48 +00:00
console Move create of ComputeAPI object in websocketproxy 2019-04-10 15:34:17 -07:00
consoleauth Fix stacktraces with redis caching backend 2018-10-01 07:50:53 +00:00
db Replace usage of get_legacy_facade() with get_engine() 2018-10-10 13:54:07 +01:00
hacking Use nova.db.api directly 2018-07-10 14:56:27 +00:00
image Fix regression in glance client call 2019-04-23 14:09:40 +00:00
ipv6
keymgr
locale Imported Translations from Zanata 2019-01-06 07:42:59 +00:00
network Fix port dns_name reset 2019-01-30 14:12:14 +00:00
notifications Remove noisy DEBUG log 2018-08-24 11:19:14 +02:00
objects Do not persist RequestSpec.ignore_hosts 2019-04-02 09:36:10 -04:00
pci PCI: do not force remove allocated devices 2019-02-05 23:29:36 +00:00
policies Remove support for /os-floating-ip-dns REST API 2018-07-18 22:23:45 -04:00
privsep Make supports_direct_io work on 4096b sector size 2018-11-21 14:14:22 +00:00
scheduler Fix bug preventing forbidden traits from working 2019-04-03 11:44:16 -05:00
servicegroup Fix service list for disabled compute using MC driver 2018-09-14 02:25:10 +00:00
tests AZ list performance optimization: avoid double service list DB fetch 2019-04-30 13:17:04 +00:00
virt Fix {min|max}_version in ironic Adapter setup 2019-04-25 08:38:41 -05:00
vnc
volume Avoid BadRequest error log on volume attachment 2019-02-28 17:10:01 +00:00
__init__.py
availability_zones.py AZ list performance optimization: avoid double service list DB fetch 2019-04-30 13:17:04 +00:00
baserpc.py
block_device.py Add uuid column to BlockDeviceMapping 2017-12-17 14:28:35 +00:00
cache_utils.py
config.py Configure placement DB context manager for nova-manage/status 2018-09-06 10:47:55 -04:00
context.py Use nova.db.api directly 2018-07-10 14:56:27 +00:00
crypto.py Convert certificate generation to processutils. 2018-05-02 19:18:41 +10:00
debugger.py
exception.py Explicitly fail if trying to attach SR-IOV port 2018-09-25 16:22:19 +00:00
exception_wrapper.py Add full traceback to ExceptionPayload in versioned notifications 2018-06-19 16:46:46 +08:00
filters.py
hooks.py
i18n.py correct referenced url in comments 2018-01-18 09:16:37 +08:00
loadables.py
manager.py conf: Remove 'db_driver' config opt 2018-03-16 17:23:16 +00:00
policy.py
profiler.py
quota.py Merge "Avoid joins in _server_group_count_members_by_user" 2018-08-07 23:16:06 +00:00
rc_fields.py Nix unused raise_if_custom_resource_class_pre_v1_1 2018-06-18 19:52:45 +00:00
rpc.py Use oslo.messaging per-call monitoring 2018-06-11 14:44:10 -07:00
safe_utils.py
service.py Move conductor wait_until_ready() delay before manager init 2018-08-31 16:21:52 -04:00
service_auth.py Fix NoneType error when [service_user] is misconfigured 2017-11-28 12:22:30 -06:00
test.py Use nova.db.api directly 2018-07-10 14:56:27 +00:00
utils.py Harden placement init under wsgi 2018-11-12 11:30:32 +00:00
version.py
weights.py
wsgi.py Refactor WSGI apps and utils to limit imports 2018-03-06 22:05:12 +00:00