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

ShardablePhpRedis backend #7

Open
wants to merge 16 commits into
base: 8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions TODOLIST.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
TODOLIST
--------

If you want a really fast Drupal 8:

* Drupal\Core\KeyValueStore\DatabaseStorage
Drupal\Core\KeyValueStore\DatabaseStorageExpirable
Notes:
- Both are easy to implement.
- Must be able to separate it from the sharded pool since it needs to
be reliable and consistent over time. The client/server pool
implementation from 7.x-3.x must be port too.
- The first bring the complexity of the data migration.

* Drupal\Core\Routing
Notes:
- Quite easy one too
- I'm not sure if there is other components using it or not, case in
which this is not sure anymore this is easy.

* Drupal\Core\Config\DatabaseStorage
Note:
- Easy one.

* Drupal\Core\Path\AliasStorage
Note:
- Already done in 7.x-2.x version, and if the schema didn't change much
this a rather easy one too.
- If the same schema is used that the 7.x version, then there is no use
in sharding it, and should be stored along the router table replacement.

* Drupal\Core\Session\SessionHandler
Note:
- Easy one.

The first two will get rid of almost 30 out of the 50 remaining SQL queries
on a simple homepage with no content displayed. The third one will get rid of
5 or so remaining.

If all of those are took care of, it will remain less than 10 SQL queries on
a standard profile home page. After that, real profiling needs to be done over
a site with contents, blocks and views all around the place, on various pages.
2 changes: 1 addition & 1 deletion redis.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ services:
class: Drupal\redis\Cache\CacheBackendFactory
arguments: ['@redis.factory', '@cache_tags.invalidator.checksum']
redis.factory:
class: Drupal\redis\ClientFactory
class: Drupal\redis\ClientFactory
40 changes: 15 additions & 25 deletions src/Cache/CacheBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
*/
abstract class CacheBase implements CacheBackendInterface {

use RedisPrefixTrait;
use RedisPrefixTrait {
getKey as getParentKey;
}

/**
* Temporary cache items lifetime is infinite.
Expand All @@ -34,17 +36,6 @@ abstract class CacheBase implements CacheBackendInterface {
*/
const LIFETIME_PERM_DEFAULT = 31536000;

/**
* Computed keys are let's say arround 60 characters length due to
* key prefixing, which makes 1,000 keys DEL command to be something
* arround 50,000 bytes length: this is huge and may not pass into
* Redis, let's split this off.
* Some recommend to never get higher than 1,500 bytes within the same
* command which makes us forced to split this at a very low threshold:
* 20 seems a safe value here (1,280 average length).
*/
const KEY_THRESHOLD = 20;

/**
* Latest delete all flush KEY name.
*/
Expand Down Expand Up @@ -132,18 +123,6 @@ public function invalidate($cid) {
$this->invalidateMultiple([$cid]);
}

/**
* Return the key for the given cache key.
*/
public function getKey($cid = NULL) {
if (NULL === $cid) {
return $this->getPrefix() . ':' . $this->bin;
}
else {
return $this->getPrefix() . ':' . $this->bin . ':' . $cid;
}
}

/**
* Calculate the correct expiration time.
*
Expand All @@ -158,7 +137,7 @@ protected function getExpiration($expire) {
if ($expire == Cache::PERMANENT || $expire > $this->permTtl) {
return $this->permTtl;
}
return $expire - REQUEST_TIME;
return $expire - time();
}

/**
Expand Down Expand Up @@ -205,4 +184,15 @@ public function setPermTtl($ttl = NULL) {
}
}

/**
* {@inheritdoc}
*/
public function getKey($parts) {
if (is_string($parts)) {
$parts = [$parts];
}
array_unshift($parts, $this->bin);
return $this->getParentKey($parts);
}

}
Loading