Skip to content

Commit e3ff314

Browse files
committed
Amazon ElastiCache Caching for RDS Solutions Guidance
1 parent 7cb0c17 commit e3ff314

File tree

4 files changed

+143
-39
lines changed

4 files changed

+143
-39
lines changed

guidance/README.md

+13-19
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ You are responsible for the cost of the AWS services used while running this Gui
2929
As of 03/28/2024, the cost for running this guidance with the default settings using AWS ElastiCache instance type cache.t2.x.small utilizing 1 primary, in the US East (N. Virginia) for on-demand pricing is approximately $24.82 USD total per month. AWS The RDS database cost is estimated at $14.71. However, cost will greatly depend on the, instance size, and RDS licensing model selected. Reserved instance pricing will reduce cost for both RDS and ElastiCache. ElastiCache is also available in a serverless offering where pay-per-consumption cost model is applicable.
3030

3131
| Service | Assumptions | Estimated Cost Per Month |
32-
| --------------------- | ------------------------------------------------- | ------------- |
33-
| Amazon ElastiCache | 2 Instance (cache.t2.small) used for 730 hours | $24.82 |
34-
| Amazon RDS MySQL | 1 Instance (db.t3.micro) used for 730 hours | $14.71 |
32+
| --------------------- | ------------------------------------------------- | ------------- |
33+
| Amazon ElastiCache | 2 Instance (cache.t2.small) used for 730 hours | $24.82 |
34+
| Amazon RDS MySQL | 1 Instance (db.t3.micro) used for 730 hours | $14.71 |
3535

3636

3737
## Prerequisites
3838

39-
This guidance is targeted towards those familiar with the AWS RDS Service. The users are expected to have a basic understanding of AWS RDS service and database access patterns. It guides users how to utilize AWS ElastiCache in addition to their existing relational database. Effectively paring your database with a caching service. It should be run in US East N.Virginia region.
39+
This guidance is targeted towards those familiar with the AWS RDS Service. The users are expected to have a basic understanding of AWS RDS service and database access patterns. It guides users how to utilize AWS ElastiCache in addition to their existing relational database. Effectively paring your database with a caching service. It should be run in US East N.Virginia region. This guidance is not intended for production workloads. For example, recommended security configurations are not included. For production systems it is strongly recommended that data should be encrypted both in transit and at rest.
4040

4141

4242
### Operating System
@@ -76,9 +76,9 @@ All regions where AWS RDS MySQL and AWS ElastiCache are offered.
7676
3. Clone the repository by executing ```git clone <repo name> ```
7777
4. Change directory to the guidance directory ```cd guidance```
7878
5. Execute the setup_host script ```./setup_host.sh```
79-
6. Log in to the same instance from a separate session and navigate to the same directory and execute ```./setup_jupyter.sh``` script.
80-
7. In your computer browser enter the EC2's public IP address and port for example ```http://1.2.3.4:8888`` Note that this is not a secured service.
81-
8. Enter the preset password for your Jupyter notebook "test123"
79+
6. Log in to the same instance from a separate session and navigate to the same directory and execute ```./setup_jupyter.sh``` script. Enter the initial password. Commit this to memory as you will have to enter it once the notebook is running.
80+
7. In your computer browser enter the EC2's public IP address and port for example ```http://1.2.3.4:8888`` Note: that jupyter configuration is not a secured as it is running the http (no s) protocol. In order to secure jupyter notebook please configure https protocol as documented here: https://jupyter-notebook.readthedocs.io/en/6.2.0/public_server.html#running-a-public-notebook-server
81+
8. Enter the password for your Jupyter notebook. (The password entered at step 6)
8282
9. In your first session edit the .env file and update it with your database and ElastiCache related information.
8383
10. Source the .env file ```source .env``` to export the parameters.
8484

@@ -88,26 +88,20 @@ It is not part of this guidance to install and configure client applications for
8888

8989
## Running the Guidance
9090

91-
* Execute the `scenario01.py` script. This workload accesses the database only and captures command level performance data in a logfile. In the directory where you executed the `setup_host.sh` and the Python virtual environment is activated, the first connection, execute:
92-
```bash
93-
(.venv) [ec2-user]$ python scenario01.py --users 10 --queries 1000 --read_rate 80
94-
```
95-
91+
* Execute the scenario01.py script. This workload accesses the database only and captures command level performance data in a logfile. In the directory where you executed the setup_host.sh and the Python virtual environment is activated, the first connection, execute: ```python scenario01.py --users 10 --queries 1000 --read_rate 80```
9692
* If deployment was correct you should see a response similar to this. (small sample execution)
97-
98-
```bash
93+
9994
(.venv) [ec2-user]$ python scenario01.py --users 1 --queries 10 --read_rate 80
10095
Reads: 8
10196
Writes: 2
10297
Logfile located here: logs/scenario01_139007_mwae8c4k.json
103-
```
104-
* Open the Jupyter notebook `plot_results_db_only.ipynb` file and update the logfile name in the second cell. For example ```log_pattern = 'scenario01_139007_mwae8c4k.json```
98+
99+
* Open the Jupyter notebook plot_results_db_only.ipynb file and update the logfile name in the second cell. For example ```log_pattern = 'scenario01_139007_mwae8c4k.json```
105100

106101
* From the run option select run all cells. The output of the last cell will show both the number of executions per second and the average response time.
107102

108103
* To compare the performance boost provided by ElastiCache repeat the above steps but use the scenario02.py script. For example execute ```python scenario02.py --users 1 --queries 10 --read_rate 80``` The output should be similar.
109104

110-
```bash
111105
(.venv) [ec2-user]$ python scenario02.py --users 1 --queries 10 --read_rate 80
112106
Connected to Database
113107
Connected to ElastiCache
@@ -116,9 +110,8 @@ Writes: 0
116110
Cache hits: 10
117111
Cache misses: 0
118112
Logfile located here: logs/scenario02_176908_0y2qr55f.json
119-
```
120113

121-
* Open the Jupyter notebook `plot_results_db_and_cache.ipynb` file and update the logfile name in the second cell. For example ```log_pattern = 'scenario02_176908_0y2qr55f.json```
114+
* Open the Jupyter notebook plot_results_db_and_cache.ipynb file and update the logfile name in the second cell. For example ```log_pattern = 'scenario02_176908_0y2qr55f.json```
122115

123116
Then select run all cells to plot the performance of the second scenario. Note that a small execution may not be sufficient to demonstrate the performance advantage of adding a cache.
124117

@@ -148,3 +141,4 @@ For feedback please access the github page <here>
148141
Include a legal disclaimer
149142

150143
*Customers are responsible for making their own independent assessment of the information in this Guidance. This Guidance: (a) is for informational purposes only, (b) represents AWS current product offerings and practices, which are subject to change without notice, and (c) does not create any commitments or assurances from AWS and its affiliates, suppliers or licensors. AWS products or services are provided “as is” without warranties, representations, or conditions of any kind, whether express or implied. AWS responsibilities and liabilities to its customers are controlled by AWS agreements, and this Guidance is not part of, nor does it modify, any agreement between AWS and its customers.*
144+

guidance/guidance-ec2.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
# SPDX-License-Identifier: MIT-0
3-
41
AWSTemplateFormatVersion: '2010-09-09'
52
Transform: 'AWS::Serverless-2016-10-31'
63
Description: Create and EC2 to demonstrate the benefits of pairing RDBMS workloads with AWS ElastiCache
@@ -74,6 +71,7 @@ Resources:
7471
ImageId: ami-0d8f91fa8ecdc3b58
7572
KeyName: !Ref AppInstanceKeyName
7673
Monitoring: true
74+
DisableApiTermination: true
7775
SecurityGroupIds:
7876
- !Ref AppInstanceSecurityGroup
7977
SubnetId: !Ref AppInstanceSubnet
@@ -88,4 +86,4 @@ Resources:
8886
Tags:
8987
-
9088
Key: Name
91-
Value: !Ref AppInstanceName
89+
Value: !Ref AppInstanceName

guidance/requirements.txt

+104-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,111 @@
1-
python-decouple==3.8
2-
redis==5.0.4
3-
SQLAlchemy==2.0.30
4-
jupyter-events==0.6.3
5-
jupyter-server==1.24.0
1+
aiofiles==22.1.0
2+
aiosqlite==0.19.0
3+
anyio==3.7.1
4+
argon2-cffi==23.1.0
5+
argon2-cffi-bindings==21.2.0
6+
arrow==1.2.3
7+
async-timeout==4.0.3
8+
attrs==23.2.0
9+
Babel==2.14.0
10+
backcall==0.2.0
11+
beautifulsoup4==4.12.3
12+
bleach==6.0.0
13+
cached-property==1.5.2
14+
certifi==2024.2.2
15+
cffi==1.15.1
16+
charset-normalizer==3.3.2
17+
cycler==0.11.0
18+
debugpy==1.7.0
19+
decorator==5.1.1
20+
defusedxml==0.7.1
21+
entrypoints==0.4
22+
exceptiongroup==1.2.0
23+
fastjsonschema==2.19.1
24+
fonttools==4.38.0
25+
fqdn==1.5.1
26+
greenlet==3.0.3
27+
idna==3.6
28+
importlib-metadata==6.7.0
29+
importlib-resources==5.12.0
30+
ipykernel==6.16.2
31+
ipython==7.34.0
32+
ipython-genutils==0.2.0
33+
isoduration==20.11.0
34+
jedi==0.19.1
35+
Jinja2==3.1.3
36+
json5==0.9.16
37+
jsonpointer==2.4
38+
jsonschema==4.18.0
39+
jupyter-events==0.9.0
40+
jupyter-server==2.14.1
641
jupyter-ydoc==0.2.5
742
jupyter_client==7.4.9
843
jupyter_core==4.12.0
944
jupyter_server_fileid==0.9.1
1045
jupyter_server_ydoc==0.8.0
1146
jupyterlab==3.6.7
1247
jupyterlab-pygments==0.2.2
13-
jupyterlab_server==2.24.0
48+
jupyterlab_server==2.24.0
49+
kiwisolver==1.4.5
50+
markdown-it-py==2.2.0
51+
MarkupSafe==2.1.5
52+
matplotlib==3.5.3
53+
matplotlib-inline==0.1.6
54+
mdurl==0.1.2
55+
mistune==3.0.2
56+
nbclassic==1.0.0
57+
nbclient==0.7.4
58+
nbconvert==7.6.0
59+
nbformat==5.8.0
60+
nest-asyncio==1.6.0
61+
notebook==6.5.6
62+
notebook_shim==0.2.4
63+
numpy==1.21.6
64+
packaging==24.0
65+
pandas==1.3.5
66+
pandocfilters==1.5.1
67+
parso==0.8.3
68+
pexpect==4.9.0
69+
pickleshare==0.7.5
70+
Pillow==9.5.0
71+
pkgutil_resolve_name==1.3.10
72+
prometheus-client==0.17.1
73+
prompt-toolkit==3.0.43
74+
psutil==5.9.8
75+
ptyprocess==0.7.0
76+
pycparser==2.21
77+
Pygments==2.17.2
78+
PyMySQL==1.1.0
79+
pyparsing==3.1.2
80+
pyrsistent==0.19.3
81+
python-dateutil==2.9.0.post0
82+
python-decouple==3.8
83+
python-json-logger==2.0.7
84+
pytz==2024.1
85+
PyYAML==6.0.1
86+
pyzmq==24.0.1
87+
redis==5.0.3
88+
requests==2.31.0
89+
rfc3339-validator==0.1.4
90+
rfc3986-validator==0.1.1
91+
rich==13.7.1
92+
Send2Trash==1.8.2
93+
six==1.16.0
94+
sniffio==1.3.1
95+
soupsieve==2.4.1
96+
SQLAlchemy==2.0.29
97+
terminado==0.17.1
98+
tinycss2==1.2.1
99+
tomli==2.0.1
100+
tornado==6.2
101+
traitlets==5.9.0
102+
typing_extensions==4.7.1
103+
uri-template==1.3.0
104+
urllib3==1.26.6
105+
wcwidth==0.2.13
106+
webcolors==1.13
107+
webencodings==0.5.1
108+
websocket-client==1.7.0
109+
y-py==0.6.2
110+
ypy-websocket==0.8.4
111+
zipp==3.15.0

guidance/setup_jupyter.sh

100755100644
+24-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
#!/bin/bash
22
#
3-
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4-
# SPDX-License-Identifier: MIT-0
5-
63
# debug flags
7-
# set -ex
4+
#set -ex
85
source .venv/bin/activate
96

10-
echo 'y' | jupyter notebook --generate-config
7+
# Save old configuration file if exits
8+
JUPYTER_CONFIG="$HOME/.jupyter/jupyter_lab_config.py"
9+
10+
mv ${JUPYTER_CONFIG} ${JUPYTER_CONFIG}_$(date +%F-%T)
11+
12+
echo 'y' | jupyter lab --generate-config
13+
14+
read -s -p "Password: " PASSWORD
15+
16+
echo ""
17+
echo "entered passwrord ${PASSWORD}"
18+
PASSWORD=$(python -c "from jupyter_server.auth import passwd; print(passwd('${PASSWORD}'))")
19+
20+
echo "before"
21+
cat ${JUPYTER_CONFIG} | grep 'c.ServerApp.password'
22+
23+
sed -i "s|# c.ServerApp.password = ''|c.ServerApp.password = '${PASSWORD}'|g" ${JUPYTER_CONFIG}
1124

12-
PASSWORD=$(python -c "from jupyter_server.auth import passwd; print(passwd('test123'))")
25+
echo "after"
26+
cat ${JUPYTER_CONFIG} | grep 'ServerApp.password'
1327

14-
sed -i "s|# c.NotebookApp.password = ''|c.NotebookApp.password = '${PASSWORD}'|g" ~/.jupyter/jupyter_notebook_config.py
15-
sed -i "s/# c.NotebookApp.ip = 'localhost'/c.NotebookApp.ip='0.0.0.0'/g" ~/.jupyter/jupyter_notebook_config.py
16-
sed -i "s/# c.NotebookApp.port = 8888/c.NotebookApp.port = 8888/g" ~/.jupyter/jupyter_notebook_config.py
17-
sed -i "s/# c.NotebookApp.open_browser = True/c.NotebookApp.open_browser = False/g" ~/.jupyter/jupyter_notebook_config.py
28+
sed -i "s/# c.ServerApp.allow_password_change = True/c.ServerApp.allow_password_change = True/g" ${JUPYTER_CONFIG}
29+
sed -i "s/# c.ServerApp.ip = 'localhost'/c.ServerApp.ip='0.0.0.0'/g" ${JUPYTER_CONFIG}
30+
sed -i "s/# c.ServerApp.port = 8888/c.ServerApp.port = 8888/g" ${JUPYTER_CONFIG}
31+
sed -i "s/# c.ServerApp.open_browser = True/c.ServerApp.open_browser = False/g" ${JUPYTER_CONFIG}
1832

1933
jupyter lab &

0 commit comments

Comments
 (0)