문제

I have a concept that I want to get peoples opinions on for running sessions in AWS with the redundancy of DynamoDB and the speed of Elasticache.

  1. PHP stores sessions in DynamoDB.
  2. When sessions are written to DynamoDB the values are also written to Elasticache (possibly stored as JSON in one key pair for fast entire retrieval.
  3. PHP then queries Elasticache for sessions.
  4. If PHP can't find a session in Elasticache it checks DynamoDB - therefore providing a backup for node failure, cluster failure and site failure. If the session is found its written back to Elasticache (if possible) and if not a new session is created in DynamoDB.

Good, bad, messy, to complex??

도움이 되었습니까?

해결책

No, it's not bad/complex--that's a pretty standard usage of memcache as a write-through cache of a persistent data store. However, it's a really expensive solution from monthly AWS billing perspective.

Have you benchmarked using just DynamoDB at all? It's an SSD-backed key-value store that ought to be plenty fast enough. I say "ought to" though, because I had issues with horrible latency when I attempted to do the same thing on it. We ended up moving purely to an ElasticCache solution and simply live with the possibility of node failure. But this was for an existing application that was shoe-horned onto AWS in a hurry and was using ridiculously large session objects. I haven't had time to revisit the idea.

다른 팁

To add to what jamieb said, here are some links:

If you are going to use ElastiCache, I suggest using their auto-discovery feature so you only have to worry about one memcache endpoint regardless of how many cache nodes there actually are.

If you are going to use DynamoDB, you should use the DynamoDB Session Handler provided by the AWS SDK for PHP. Here is a simple code sample for how to use the session handler:

<?php

// Load SDK via Composer autoloader
require 'vendor/autoload.php';

// Instantiate the SDK with your config
$aws = Aws\Common\Aws::factory('/path/to/config/file');

// Instantiate the DynamoDB client and register the session handler
$db = $aws->get('dynamodb');
$db->registerSessionHandler(array(
    'table_name' => 'sessions',
    'hash_key'   => 'id',
));

// Use PHP sessions like normal
session_start();
$_SESSION['foo'] = 'bar';
session_commit();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top