we are currently using a NAS for PHP session files storage for an array of autoscaling load balanced app servers.
We are interested to replace this with a more robust solution and DynamoDB from Amazon looks interesting. I see one possible issue here, documented here:
http://thwartedefforts.org/2006/11/11/race-conditions-with-ajax-and-php-sessions/
I suspect DynamoDB does not support object locking. Any workarounds you can think of?
If you have any experience from other NoSQL systems used for PHP sessions also feel free to jump in as the learnings might be similar.
Thanks in advance
Using DynamoDB for session storage alleviates issues that occur with session handling in a distributed web application by moving sessions off of the local file system and into a shared location. DynamoDB is fast, scalable, easy to set up, and handles replication of your data automatically.
Even though the solution has many benefits, one of the major drawbacks is that the solution lacks an on-premise deployment model and is only available on the AWS cloud. This limitation does not allow users to use DynamoDB for applications that require an on-premise database.
Amazon DynamoDB transactions simplify the developer experience of making coordinated, all-or-nothing changes to multiple items both within and across tables. Transactions provide atomicity, consistency, isolation, and durability (ACID) in DynamoDB, helping you to maintain data correctness in your applications.
In this post, I show you how to use such an anti-pattern for DynamoDB, but it is a great fit for time-series data. Unless you opt for on-demand capacity mode, every DynamoDB access pattern requires a different allocation of read capacity units and write capacity units.
Using DynamoDB's conditional writes, you could implement a pessimistic locking scheme similar to the way PHP's default session handler works.
Someone else has also made a request for a DynamoDB session handler: https://forums.aws.amazon.com/thread.jspa?messageID=328060.
Updated: The AWS SDK for PHP now includes a session handler for DynamoDB. See https://github.com/amazonwebservices/aws-sdk-for-php/blob/master/extensions/dynamodbsessionhandler.class.php and http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#i=DynamoDBSessionHandler
Updated: There is an article about the DynamoDB session handler on the AWS blog: http://aws.typepad.com/aws/2012/04/scalable-session-handling-in-php-using-amazon-dynamodb.html
Interesting idea (+1) - and an elaborate article indeed, just skimmed it for now though ;)
Regarding other NoSQL options for PHP session storage you might want to check out MongoSession – A PHP MongoDB Session Handler, which references Race Conditions with Ajax and PHP Sessions as well and seems to address the documented issues in the meantime:
I have recently updated the library to support atomic operations on both session writes and garbage collection to help prevent these race conditions.
A similar approach should be possible with Amazon DynamoDB as well by means of an appropriate combination of Conditional Updates, Atomic Counters and Consistent Reads, see Working with Items in Amazon DynamoDB for details on those concepts and/or check out the following FAQ entries:
Your servers are on AWS? Why don't you try the ElastCache feature? http://aws.amazon.com/en/elasticache/
I use CakePHP, witch supports DB and Memcache to store sessions. After some some time studding both, I've opted for Memcache. Actually, I set PHP to store sessions on Memcache and set CakePHP to use php sessions config. This way I can separate my memcache instances for sessions and caching.
Regards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With