pushiqiang / django_forum Goto Github PK
View Code? Open in Web Editor NEWThis is a small and simple forum which uses the Django Framework (written in Python language).这是一个基于django的小型论坛系统
This is a small and simple forum which uses the Django Framework (written in Python language).这是一个基于django的小型论坛系统
As you know, Django uses new database connection for each request. This works well initially. However as the load on the server increases, creating/destroying connections to database starts taking significant amount of time. You will find many questions about using some kind of connection pooling for Django on sites like StackOverflow For example, Django persistent database connection.
At BootStrap Today we use sqlalchemy‘s connection pooling mechanism with Django for pooling the database connections. We use variation of approach by Igor Katson described in http://dumpz.org/67550/. Igor’s approach requires patching Django which we wanted to avoid. Hence we created a small function that we import in one of init.py (or models.py) (i.e. some file which gets imported early in the application startup).
CODE:
import sqlalchemy.pool as pool
pool_initialized=False
def init_pool():
if not globals().get('pool_initialized', False):
global pool_initialized
pool_initialized = True
try:
backendname = settings.DATABASES['default']['ENGINE']
backend = load_backend(backendname)
#replace the database object with a proxy.
backend.Database = pool.manage(backend.Database)
backend.DatabaseError = backend.Database.DatabaseError
backend.IntegrityError = backend.Database.IntegrityError
logging.info("Connection Pool initialized")
except:
logging.exception("Connection Pool initialization error")
#Now call init_pool function to initialize the connection pool. No change required in the
# Django code.
init_pool()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.