Resolving the performance issue for image listing of v2 API on server

This is a fix on Glance server side regarding to the former change
Ia6598d3c06a5ff516277053c2b6fa5db744fe9cf for glanceclient.

This change optimized the logic of image query in glance.db.ImageRepo
which running in glance-api server and communicated with glance-registry
service by HTTP based RPC calls. Under original logic, each image entry
in the (paginated) result set query RPC returned needs to query the
relevant tag entry set by a separated RPC again, so for example if we
have 1000 images, and page size equals 20, then the count of RPC calls
will be 1099 times. With fixed new logic, the RPC times have been
reduced, it merged the queries of image and its tag entry into one RPC
call.

As comparison [0], under the fixed new logic, the execution time of
image listing is about 2.5 times as fast as old logic (using
glanceclient cli with registry backend). Then the execution time of v2
api is better then v1 now[1] (about 2 times faster).

[0]
# Original logic

# glanceclient cli, with registry
$ time glance --os-image-api-version 2 image-list | grep 'test-' | wc -l
1000
real	0m10.210s
user	0m1.244s
sys	0m0.080s

# curl, with registry
$ time ./img1000-curl-v2.sh > /dev/null 2>&1
real	0m9.185s
user	0m0.168s
sys	0m0.108s

# Fixed logic

# glanceclient cli, with registry
$ time glance --os-image-api-version 2 image-list | grep 'test-' | wc -l
1000
real	0m3.870s
user	0m1.364s
sys	0m0.076s

# curl, with registry
$ time ./img1000-curl-v2.sh > /dev/null 2>&1
real	0m2.718s
user	0m0.160s
sys	0m0.136s

[1]
$ time glance --os-image-api-version 1 image-list | grep 'test-' | wc -l
1000
real	0m7.426s
user	0m0.936s
sys	0m0.100s

Change-Id: I3402e4594fa945d003a6735c54581fc43d07c6da
Signed-off-by: Zhi Yan Liu <zhiyanl@cn.ibm.com>
Merge "Resolving the performance issue for image listing of v2 API on server"