Skip to content

Commit

Permalink
Enable connection pooling
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Nov 13, 2024
1 parent 5648fd1 commit 92cb81b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions crank/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under the MIT License. See LICENSE file in the project root for full license information.
import os
import pymysql
import multiprocessing
from pathlib import Path

pymysql.install_as_MySQLdb()
Expand All @@ -13,15 +14,21 @@
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
CSRF_COOKIE_SECURE = True
CPU_COUNT = multiprocessing.cpu_count()

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ.get('DB_NAME'),
'HOST': os.environ.get('DB_HOST'),
'PORT': os.environ.get('DB_PORT'),
'USER': os.environ.get('DB_USER'),
'PASSWORD': os.environ.get('DB_PASS')
# 'OPTIONS': {'ssl': {'ca': os.environ.get('MYSQL_ATTR_SSL_CA')}}
'PASSWORD': os.environ.get('DB_PASS'),
'CONN_MAX_AGE': 0, # Use 0 for connection pooling
'OPTIONS': {
'MAX_CONNS': CPU_COUNT * 4, # Maximum number of connections in the pool
'REUSE_CONNS': CPU_COUNT * 2, # Number of connections to reuse
},
}
}
ALLOWED_HOSTS = ['*']
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cffi==1.17.0rc1
charset-normalizer==3.3.2
click==8.1.7
coverage==7.3.2
cryptography==43.0.1
cryptography==43.0.3
defusedxml==0.7.1
Deprecated==1.2.14
distlib==0.3.8
Expand Down

0 comments on commit 92cb81b

Please sign in to comment.