I'm using drupal 7.33 - php 5.4
I have many roles (17). When I change some data in the profile page I get the following error.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 46 bytes) in /var/www/html/MY_SITE/sites/all/modules/authcache/modules/authcache_enum/authcache_enum.comb.inc on line 94

If I reduce the number of roles which are using authcache, the problem disappear.

Look like the code in the patch on this post should solve the problem but the code is totally different from the actual version.
I've checked the versions: 7.x-2.0-beta3+31-dev and 7.x-2.0-beta4 but the code is different than the patch.

Is there a way to correct the problem or at least a work around ?

Thank !!

Comments

znerol’s picture

Assigned: daniele belitrandi » Unassigned

Please explain a bit your use-case. Do you have any scheme on how the roles are assigned to users? Are there any role-combinations which never will occure? Can you formulate (in words) a set of rules which role combinations are to be expected?

daniele belitrandi’s picture

I have 5 main roles:
- anonymous
- admin (which is a new role, Not drupal default. This role has access to almost everything and only 1 user is assigned to it)
- Master Publisher (has access to manage all the site content but do not have access to site configuration. just 1/2 user will have this role)
- Master Editor (has access to create/edit/delete node of only some content type and can publish the node, Few user will have this role).
- Editor (has access to create/edit/delete node of only some content type but cannot publish the node, only create draft node).

Then I have 13 different roles which give just 1 permission to access just 1 content type for each role. For example:

the role "Ad Banner city" give access to the content type "Ad Banner city"
the role "Ad Banner Country" give access to the content type "Ad Banner country"
the role "Ad Column city" give access to the content type "Ad column city"
.........and so on for 13 roles..............

As per default the role "Editor" is assigned to the user which give access to some content type. If the user want to purchase a banner ad, I will assign also the role "Ad Banner city". So the user will have 2 roles: "Editor" and "Ad Banner city".

I tested different combination of assigned roles to authcache.
What I found out is that doesn't matter which role is assigned to autcache and if the role give a lot of permission or just few of them.
The problem lay only on the quantity of roles. In my environment if I assign 17 roles everything is fine but in the moment I assign the eighteen role, the error come up.

I can live with that because it is only one role less than my need, but maybe my test result can be useful for someone.

Thanks for your reply and have a nice day.

znerol’s picture

Authcache Enum tries to discover every possible authcache key. It does this by enumerating every combination of roles. In order to solve your problem it might be enough to limit the number of combinations.

Maybe this is possible by determining the maximum of existing role combinations instead of blindly work with all the combinations which are theoretical possible. I.e. select the user with the most roles and only build combinations of roles up to that number. However, this obviously will not work if there is at least one user having (nearly) all roles assigned.

In order to asses whether restricting the cardinality would solve the problem in your case, please save the following PHP snipped into a file in your websites root directory and run it once, then post the result here:

define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$roles = array_keys(authcache_get_roles());

$t0 = microtime(TRUE);
$k_max = db_query('SELECT MAX(k) FROM (SELECT DISTINCT count(rid) AS k FROM {users_roles} WHERE rid IN (:roles) GROUP BY uid) AS cardinalities', array(':roles' => $roles))->fetchField();
$t1 = microtime(TRUE);
$dt = ($t1 - $t0);

print "k_max=${k_max};dt=${dt}";

The output should look similar to this:
k_max=2;dt=0.00018405914306641

znerol’s picture

Status: Active » Postponed (maintainer needs more info)
Matroschker’s picture

Hello,

I got a similar error message in my system:

PHP Fatal error: Out of memory (allocated 1695023104) (tried to allocate 36 bytes) in C:\\...\\sites\\all\\modules\\authcache\\modules\\authcache_enum\\authcache_enum.comb.inc on line 29, referer: ...

... so I tried to patch the authcache.module with the patch from here "https://www.drupal.org/node/1963756" but the code is different, so now way to do this. (Checked with current DEV-version from 2015-01-02)

.. and I run your PHP code on my site, here is the result: k_max=119;dt=0.015625

Thanks for helping
Matroschker

znerol’s picture

@Matroschker these numbers indicate that there are at least 119 authcache enabled roles at the site in question. Is this really true?

Matroschker’s picture

Hi znerol,

yes it's true. But I checked this also with 45 roles - the same effect.

Matroschker

znerol’s picture

Can you estimate how many users you have per role-combination?

Matroschker’s picture

znerol,

not really. We have ~10 roles which defines the permissions for the kind of worker and a lot of product roles, which we use to give access to special content.
Can you explain why it is necessary that all roles, an user have, must selected in the authcache configuration that the caching works?

Matroschker

znerol’s picture

I'd like to point out the following things about Authcache;

  1. When assessing caching performance, the cache hit/miss ratio is the key-indicator.
  2. Hence it is most effective on sites where a big number of users share a small number of role combinations.
  3. On sites where there are not many users sharing role combinations, the cache-hit/miss ratio will be poor. This is because each role-combination will generate a distinct cache-key, i.e. one page will be cached separately for each group of users (where group = users with common role combination).
  4. It cannot speed up a slow backend. If your users mainly edit content, then do not use it.

As a rule of thumb if you end up selecting more than a small number of roles (perhaps at most 10) in Authcache, then you most probably should not use it at all.

Matroschker’s picture

Ok, thank you for these information, we will consider these.
Can you recommend another cache modul?
PS: We have no free content only content which is available for authenticated users.

Thank you.

znerol’s picture

Perhaps post this question to the High Performance group on groups.drupal.org.

Matroschker’s picture

Now we could solve the performance issue on our site with an update of PHP to version 5.6 to enable built in OpCache and an enabled Memcached and Memcached Storage.

Thank you for your help.
(Drupal 7.34)

socialnicheguru’s picture

I have multiple roles but would like the option to select authenticated users (no other roles) and authorized user (any other roles). The latter would just cache anyone who is has the authenticated user role regardless of any other roles they might have.

znerol’s picture

@SocialNicheGuru This is not something which could be solved safely in a generic way, but it can be achieved by customizing the Customizing authcache key calculation as explained in Authcache 2 tuning guide - optimize cache-hit ratio.

joelpittet’s picture

k_max=4;dt=0.025913953781128

killes@www.drop.org’s picture

I've also run into this but I resolved to not cache for most of the roles as the people who have these roles are few and they are unlikely to get a good cache hit ratio anyway.

Sneakyvv’s picture