Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get cache options from configuration #2769

Merged
merged 1 commit into from
Oct 20, 2017
Merged

get cache options from configuration #2769

merged 1 commit into from
Oct 20, 2017

Conversation

remicollet
Copy link
Contributor

@remicollet remicollet commented Sep 18, 2017

See #2712

Tested adapters, see https://zendframework.github.io/zend-cache/storage/adapter/:

  • none (cache disabled)
  • APCu
  • Dba
  • Filesystem
  • Memcache
  • Memcached (igbinary as default serializer)
  • Redis

To test other cache adapters: add in glpi_configs, context = core, name = cache_db or cache_trans and for value, see tested examples:

(empty = no cache)
{"adapter":"apcu"}
{"adapter":"redis","options":{"server":{"host":"127.0.0.1"}},"plugins":["serializer"]}
{"adapter":"filesystem"}
{"adapter":"filesystem","options":{"cache_dir":"_cache_trans"},"plugins":["serializer"]}
{"adapter":"dba"}
{"adapter":"dba","options":{"pathname":"trans.db","handler":"flatfile"},"plugins":["serializer"]}
{"adapter":"memcache","options":{"servers":["127.0.0.1"]}}
{"adapter":"memcached","options":{"servers":["127.0.0.1"]}}

@remicollet
Copy link
Contributor Author

remicollet commented Sep 18, 2017

@tomolimo your test welcome, especially when WinCache (IIS only) is available (and APCu is not)

@remicollet
Copy link
Contributor Author

remicollet commented Oct 10, 2017

Some bench results

+ Entities: 299598
+ Cache: disabled
+ Clear sons cache
+ Run with empty cache
> time: 2.7468
+ Run with populated cache
> time: 2.4121
+ Done

+ Entities: 299598
+ Cache: Zend\Cache\Storage\Adapter\Apcu
+ Clear sons cache
+ Run with empty cache
> time: 2.8290
+ Run with populated cache
> time: 0.0335
+ Done

+ Entities: 299598
+ Cache: Zend\Cache\Storage\Adapter\Memcache
+ Clear sons cache
+ Run with empty cache
> time: 3.0366
+ Run with populated cache
> time: 0.1195
+ Done

+ Entities: 299598
+ Cache: Zend\Cache\Storage\Adapter\Redis
+ Clear sons cache
+ Run with empty cache
> time: 2.9524
+ Run with populated cache
> time: 0.1247
+ Done

@tomolimo
Copy link
Contributor

tomolimo commented Oct 10, 2017

Hello,
At start of GLPI, I got these errors:

Uncaught Zend\Cache\Exception\RuntimeException: wincache_ucache_add('glpi_cache_db_9.3-dev:glpi_entities_ancestors_cache_0', <array>, 0) failed in C:\Projects\glpi-master\vendor\zendframework\zend-cache\src\Storage\Adapter\WinCache.php:300

Stack trace:

#0 C:\Projects\glpi-master\vendor\zendframework\zend-cache\src\Storage\Adapter\AbstractAdapter.php(790): Zend\Cache\Storage\Adapter\WinCache->internalAddItem('glpi_entities_a...', Array)

#1 C:\Projects\glpi-master\inc\dbutils.class.php(874): Zend\Cache\Storage\Adapter\AbstractAdapter->addItem('glpi_entities_a...', Array)

#2 C:\Projects\glpi-master\inc\dbutils.class.php(558): DbUtils->getAncestorsOf('glpi_entities', Array)

#3 C:\Projects\glpi-master\inc\db.function.php(739): DbUtils->getEntitiesRestrictRequest('OR', 'glpi_profiles_r...', '`glpi_profiles_...', 0, true, false)

#4 C:\Projects\glpi-master\inc\reminder.class.php(255): getEntitiesRestrictRequest('OR', 'glpi_profiles_r...', '', '', true)

#5 C:\Projects\glpi-master\inc\reminder.class.php(1074): Reminder

and

Uncaught Zend\Cache\Exception\RuntimeException: wincache_ucache_add('glpi_cache_db_9.3-dev:glpi_entities_ancestors_cache_0', <array>, 0) failed in C:\Projects\glpi-master\vendor\zendframework\zend-cache\src\Storage\Adapter\WinCache.php:300

Stack trace:

#0 C:\Projects\glpi-master\vendor\zendframework\zend-cache\src\Storage\Adapter\AbstractAdapter.php(790): Zend\Cache\Storage\Adapter\WinCache->internalAddItem('glpi_entities_a...', Array)

#1 C:\Projects\glpi-master\inc\dbutils.class.php(874): Zend\Cache\Storage\Adapter\AbstractAdapter->addItem('glpi_entities_a...', Array)

#2 C:\Projects\glpi-master\inc\dbutils.class.php(558): DbUtils->getAncestorsOf('glpi_entities', Array)

#3 C:\Projects\glpi-master\inc\db.function.php(739): DbUtils->getEntitiesRestrictRequest('OR', 'glpi_profiles_r...', '`glpi_profiles_...', 0, true, false)

#4 C:\Projects\glpi-master\inc\reminder.class.php(255): getEntitiesRestrictRequest('OR', 'glpi_profiles_r...', '', '', true)

#5 C:\Projects\glpi-master\inc\reminder.class.php(843): Reminder:

In the wincache statistics, I got this:
image

@tomolimo
Copy link
Contributor

Hello again,
The root cause is the returned code of wincache-ucache-add() (see http://php.net/manual/en/function.wincache-ucache-add.php) where it is explained that if key is already present then it will fail (i.e.: returns false). From PHP doc :

If a variable with same key is already present the function will fail and return FALSE.

regards,
Tomolimo

@tomolimo
Copy link
Contributor

tomolimo commented Oct 10, 2017

To fix the issue with Wincache, I propose to change this line

$GLPI_CACHE->addItem($ckey, $sons);

into $GLPI_CACHE->setItem($ckey, $sons);

and this line

$GLPI_CACHE->addItem($ckey, $ancestors);
into $GLPI_CACHE->setItem($ckey, $ancestors);

regards,
Tomolimo

Copy link
Contributor

@tomolimo tomolimo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests passed on IIS 7.5
Tests passed on PHP web server
LGTM

Copy link
Contributor

@trasher trasher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as well; but not tested yet (will do... asap...)

@trasher
Copy link
Contributor

trasher commented Oct 20, 2017

glpi-project/doc#17 for doc

- get cache options from configuration
- use APCu or WinCache or memcache/memcached when available
- split cache for DB and translation
- allow to disable cache in configuration
- allow plugin to use their own cache configuration for other needs
- add configuration sample (comments)
- review perf panel
- add cache benchmark script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants