oslo.policy/oslo_policy
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
..
locale Imported Translations from Zanata 2016-10-24 06:24:36 +00:00
tests Fix a code logic while doing cyclical reference check to the policy 2016-11-08 10:19:41 +08:00
__init__.py exported from oslo-incubator by graduate.sh 2014-12-09 14:40:01 -03:00
_cache_handler.py Add missing parameter description in module _cache_handler 2016-11-02 02:39:38 +00:00
_checks.py Don't crash on RoleCheck when roles not present 2016-01-02 11:59:49 -08:00
_i18n.py Update translation setup 2016-01-29 11:47:44 +01:00
_parser.py Fixes combined "and" and "or" rule handling 2015-12-13 21:39:15 +09:00
fixture.py Custom fixture to avoid external call in HttpCheck 2015-10-08 16:50:01 -07:00
generator.py Add helper scripts for generating policy info 2016-06-08 15:12:53 -04:00
opts.py Doc: declare YAML/JSON support 2016-09-22 17:09:59 +08:00
policy.py Improved performance of parse_file_contents() method 2016-11-29 23:17:31 +03:00
shell.py Deprecate load_json() in favor of load() 2016-02-22 13:17:36 -06:00
sphinxpolicygen.py Add sphinx extension to build sample policy 2016-09-28 10:59:14 +01:00
version.py Add reno for release notes management 2016-05-20 18:08:13 +03:00