Skip to content

Instantly share code, notes, and snippets.

@GrahamDumpleton
Created November 7, 2012 20:59
Show Gist options
  • Save GrahamDumpleton/4034410 to your computer and use it in GitHub Desktop.
Save GrahamDumpleton/4034410 to your computer and use it in GitHub Desktop.
Hacking Django code to work out why database connection setup is slow.
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