Sergey Nikitin f56b767ddd Improved performance of parse_file_contents() method
Before change Ic6236665f2d55b24a56a99120ac57fc2b18e32eb
policy file had been parsed by jsonutils.loads()

For some reasons jsonutils.loads() is much faster than
yaml.safe_load(). For example this script takes 30 seconds:

  s = '{"a": 3, "b": "c"}'
  for i in xrange(100000):
       yaml.safe_load(s)

And this script takes only 1 second!

  s = '{"a": 3, "b": "c"}'
  for i in xrange(100000):
      jsonutils.loads(s)

Moreover policy rules are presented in JSON format
by default (at least in Nova).

This patch proposes to parse file by jsonutils.loads().
If it was parsed - use parsed data. If it's failed - try to
parse with yaml.safe_load().

It will have no/minimum performance effect on real env because,
as I understand, we parse policy file only one time during
service start. But it will have great performance improvement
in our jenkins jobs.

Statistics for nova py27, py34 and functional jobs:

 * with this change I0c18e9746b742a2fff60795da8a5daddda7cf469
 * without this change Ie4af661f4ca16b63444692f3736835f9ce42adc1

Here was taken pure time of running "tox -e py27/py34/functional" commands

                 without (sec)         with (sec)
py27                  421                 240
py34                  330                 170
functional            662                 495

As you see performance of unit tests was increased almost in two times.

These changes covered by tests in test_policy.py file. There we
test method Rules.load() with invalid/valid JSON/YAML. As you
can see method Rules.load() directly uses parse_file_contents().

Change-Id: I43782d245d7652ba69613b26fe598ac79ec19929
2016-11-29 23:17:31 +03:00
2016-11-01 14:32:01 +08:00
2015-02-17 00:37:33 +00:00
2016-11-25 13:22:05 +01:00
2016-10-11 16:06:59 +07:00
2015-09-17 12:16:08 +00:00
2016-08-02 19:34:19 +08:00

Team and repository tags

image

oslo.policy

Latest Version

Downloads

The Oslo Policy library provides support for RBAC policy enforcement across all OpenStack services.

Description
Rules engine to enforce access control policy
Readme 6.6 MiB
Languages
Python 100%