简体   繁体   English

使用Elasticache PHP会话的AWS DynamoDB会话

[英]AWS DynamoDB Sessions with Elasticache PHP Sessions

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. 我有一个概念,我希望通过DynamoDB的冗余和Elasticache的速度让人们了解在AWS中运行会话的意见。

  1. PHP stores sessions in DynamoDB. PHP在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. 当会话写入DynamoDB时,值也会写入Elasticache(可能在一个密钥对中存储为JSON,以便快速检索整个。
  3. PHP then queries Elasticache for sessions. 然后PHP查询Elasticache以获取会话。
  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. 如果PHP无法在Elasticache中找到会话,则会检查DynamoDB - 从而为节点故障,群集故障和站点故障提供备份。 If the session is found its written back to Elasticache (if possible) and if not a new session is created in DynamoDB. 如果找到会话,则将其写回Elasticache(如果可能),如果不是,则在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. 不,它不坏/复杂 - 这是一个非常标准的memcache用法,作为持久数据存储的直写缓存。 However, it's a really expensive solution from monthly AWS billing perspective. 但是,从每月AWS结算角度来看,这是一个非常昂贵的解决方案。

Have you benchmarked using just DynamoDB at all? 您是否只使用过DynamoDB进行基准测试? It's an SSD-backed key-value store that ought to be plenty fast enough. 这是一个SSD支持的键值存储,应该足够快。 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. 我们最终纯粹转向ElasticCache解决方案,并且很容易遇到节点故障的可能性。 But this was for an existing application that was shoe-horned onto AWS in a hurry and was using ridiculously large session objects. 但这是针对现有的应用程序,该应用程序匆忙在AWS上使用,并使用了大量的会话对象。 I haven't had time to revisit the idea. 我没有时间重温这个想法。

To add to what jamieb said, here are some links: 添加到jamieb所说的内容,这里有一些链接:

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. 如果您打算使用ElastiCache,我建议使用他们的自动发现功能,这样您只需担心一个memcache端点,无论实际有多少缓存节点。

If you are going to use DynamoDB, you should use the DynamoDB Session Handler provided by the AWS SDK for PHP . 如果要使用DynamoDB,则应使用AWS SDK for PHP提供的DynamoDB会话处理程序 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM