Scaling in AWS
Create an ElastiCache Redis cache
The purpose of Redis is to share the users' states between multiple instances. Never use Redis when you are using:
- Vertical scaling (only one instance)
- Horizontal scaling with sticky sessions. Because in-memory is faster, it is a waste of performance to use a Redis cache when sticky sessions are used.
For more information, see Load balancing, sticky sessions, and Redis
For horizontal scaling without sticky sessions, you must create a Redis cache. AWS has its own ElastiCache
Redis cache.
- In the AWS console, search for 'ElastiCache', and select the resulting page.
- Click the Get started button.
- Click Create Cluster, and then Create Redis Cluster.
- In the next screen, in the Choose a cluster creation method area, click Configure and create new cluster.
- In the Cluster mode field, select Disabled.
- Enter a name and a description for Cluster info.
- In the Location part, in the Location field, select AWS Cloud, and enable Multi-AZ.
- In the Cluster settings part, leave the Engine version, Port, and Parameter group values as they are.
- In the Node type field, select a size and network speed that works for your usage. You can change these values later.
To see the difference in pricing, see this page. For Numbers of replicas, we recommend two production environments.
- In the Subnet group settings page, create a new subnet group and provide a name, optionally a description.
- Select the VPC you want to use.
- Leave the settings in the Availability Zone placements page as they are.
- Click Next. It is not necessary to enable Encryption.
- On the Security groups tab, add a security group that will be used by Elastic Beanstalk. If you do not have an Elastic Beanstalk at this time, you can add the security group later.
- In the Backup tab, disable the backup. This is not necessary because the data is short-lived.
- In the Maintenance tab, select the settings that work for your application. We recommend enabling Auto update minor versions.
- Leave the other settings as they are, and click Next.
- In this overview screen, check if all settings are correct. If not, change them as required.
- Click Create.
The Redis cache is now created.
To use the newly created Redis cache, add the following section to the appsettings.json
configuration file, and specify the Primary endpoint.
"RedisSettings": {
"ConnectionString": "<Primary endpoint>"
},
...
Now, you can deploy this to EC2 or Elastic Beanstalk.
File cache settings for Indicium
To write the cache to an AWS S3 bucket, add the following section to the appsettings.json
configuration file:
"FileCache": {
"Type": "AWSS3",
"AWSRegion": "<Name of the region the s3 bucket is hosted in>",
"AWSAccessKeyID": "<The AWS Access Key ID of the s3 bucket>",
"AWSSecretAccessKey":"<The AWS Secret Access Key of the s3 bucket>",
"AWSBucketName":"<The s3 bucket name>",
"StoragePath": "indicium-cache",
"ClearLocalCacheOnStartup": true // See explanation below
}
ClearLocalCacheOnStartup
- Optional. If not set or true
, the local cache is cleared on startup.
Set it to false
if multiple instances of Indicium share the same cache folder.
For example, when running multiple app service instances.
It prevents that one instance clears the cache while another one tries to access files in the cache.