Created
November 7, 2012 20:59
-
-
Save GrahamDumpleton/4034410 to your computer and use it in GitHub Desktop.
Hacking Django code to work out why database connection setup is slow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I changed the django code in django/db/backends/postgresql_psycopg2/base.py to: | |
self.connection = Database.connect(**conn_params) | |
with newrelic.agent.FunctionTrace(newrelic.agent.current_transaction(), 'Set client encoding'): | |
self.connection.set_client_encoding('UTF8') | |
with newrelic.agent.FunctionTrace(newrelic.agent.current_transaction(), 'Set isolation level'): | |
self.connection.set_isolation_level(self.isolation_level) | |
with newrelic.agent.FunctionTrace(newrelic.agent.current_transaction(), 'connection_created signal'): | |
connection_created.send(sender=self.__class__, connection=self) | |
if new_connection: | |
with newrelic.agent.FunctionTrace(newrelic.agent.current_transaction(), 'Cursor creation on new connection'): | |
cursor = self.connection.cursor() | |
else: | |
cursor = self.connection.cursor() | |
cursor.tzinfo_factory = None | |
if new_connection: | |
if set_tz: | |
cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment