nova/nova
Andrey Volkov 74cefe4266 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
2019-04-24 18:08:19 -04:00
..
api AZ list performance optimization: avoid double service list DB fetch 2019-04-24 18:08:19 -04:00
cells Per aggregate scheduling weight 2019-01-21 11:48:44 +08:00
cmd Stop handling cells v1 for console authentication 2019-04-16 18:26:17 +01:00
common
compute Remove old-style cell v1 instance listing 2019-04-16 18:26:17 +01:00
conductor Merge "trivial: Remove dead code" 2019-04-08 18:13:01 +00:00
conf Stop handling cells v1 for console authentication 2019-04-16 18:26:17 +01:00
console Stop handling cells v1 for console authentication 2019-04-16 18:26:17 +01:00
consoleauth Stop handling cells v1 for console authentication 2019-04-16 18:26:17 +01:00
db Merge "trivial: Remove dead nova.db functions" 2019-04-11 17:17:46 +00:00
hacking Bump to hacking 1.1.0 2019-04-12 16:23:49 +01:00
image Share snapshot image membership with instance owner 2019-02-08 18:06:27 -05:00
ipv6
keymgr
locale Imported Translations from Zanata 2019-03-22 06:26:27 +00:00
network Merge "conf: Undeprecate and move the 'dhcp_domain' option" 2019-04-16 12:48:40 +00:00
notifications Remove CellMappingPayload database_connection and transport_url fields 2019-04-04 09:59:12 -04:00
objects Drop migrate_keypairs_to_api_db data migration 2019-04-03 11:42:48 -04:00
pci Add get_instance_pci_request_from_vif 2019-03-07 11:37:53 +02:00
policies Remove '/os-cells' REST APIs 2019-04-16 18:26:13 +01:00
privsep Add test coverage for nova.privsep.qemu. 2019-04-04 20:44:01 +00:00
scheduler Change a log level for overwriting allocation 2019-04-08 16:29:10 +09:00
servicegroup Fix deprecation warning for threadgroup.add_timer 2019-02-07 09:37:00 -05:00
tests AZ list performance optimization: avoid double service list DB fetch 2019-04-24 18:08:19 -04:00
virt Fix {min|max}_version in ironic Adapter setup 2019-04-22 16:41:48 +00:00
vnc Deprecate the nova-xvpvncproxy service 2018-10-15 10:03:13 +01:00
volume Bump to hacking 1.1.0 2019-04-12 16:23:49 +01:00
__init__.py Eventlet monkey patching should be as early as possible 2019-03-22 09:27:16 +00:00
availability_zones.py AZ list performance optimization: avoid double service list DB fetch 2019-04-24 18:08:19 -04:00
baserpc.py
block_device.py Add method to generate device names universally 2019-01-15 18:55:11 +00:00
cache_utils.py
config.py Configure placement DB context manager for nova-manage/status 2018-09-05 10:29:48 -04:00
context.py Bump to hacking 1.1.0 2019-04-12 16:23:49 +01:00
crypto.py
debugger.py
exception.py Merge "Added mount fstype based validation of Quobyte mounts" 2019-04-05 17:41:13 +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
loadables.py
manager.py
monkey_patch.py Bump to hacking 1.1.0 2019-04-12 16:23:49 +01:00
policy.py Fix string interpolations in logging calls 2019-01-29 15:06:39 +09:00
profiler.py
quota.py Merge "quota: remove defaults kwarg in get_project_quotas" 2019-02-26 13:26:24 +00:00
rc_fields.py Switch to using os-resource-classes 2019-02-07 11:11:09 +00:00
rpc.py Bump to hacking 1.1.0 2019-04-12 16:23:49 +01:00
safe_utils.py
service.py Remove 'nova-cells' service 2019-04-09 17:15:37 +01:00
service_auth.py
test.py Only set oslo_messaging_notifications.driver if using RPCFixture 2019-04-19 10:52:57 -04:00
utils.py Eventlet monkey patching should be as early as possible 2019-03-22 09:27:16 +00:00
version.py
weights.py Per aggregate scheduling weight 2019-01-21 11:48:44 +08:00
wsgi.py