Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XEaLz-0000oh-3h for pgsql-jdbc@arkaria.postgresql.org; Tue, 05 Aug 2014 08:44:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XEaLx-0005iZ-5K for pgsql-jdbc@arkaria.postgresql.org; Tue, 05 Aug 2014 08:44:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XEaLv-0005iQ-92 for pgsql-jdbc@postgresql.org; Tue, 05 Aug 2014 08:44:15 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XEaLj-0000jG-Ms for pgsql-jdbc@postgresql.org; Tue, 05 Aug 2014 08:44:13 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s758htlV022373 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Aug 2014 04:43:56 -0400 Received: from [10.36.116.73] (ovpn-116-73.ams2.redhat.com [10.36.116.73]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s758hruO018182 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 5 Aug 2014 04:43:55 -0400 Message-ID: <53E09948.4070503@redhat.com> Date: Tue, 05 Aug 2014 09:43:52 +0100 From: Jeremy Whiting User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Ludwig Adam , "pgsql-jdbc@postgresql.org" Subject: Re: Trace JDBC connection to Java Thread / local socket port References: <382EC7B732854249BF4352610355BC6110AF0F95@MAIL2010.petafuel.intern> <382EC7B732854249BF4352610355BC6110C088D7@MAIL2010.petafuel.intern> In-Reply-To: <382EC7B732854249BF4352610355BC6110C088D7@MAIL2010.petafuel.intern> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Pg-Spam-Score: -6.2 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Hi Ludwig, I suggest you try using Byteman [1]. It is an invaluable tool for tracing causes of issues. When system state or concurrency needs to be detected and traced this tool was written for the purpose. The performance team I work in and other internal teams swear by it. Regards, Jeremy [1] http://www.jboss.org/byteman -- Jeremy Whiting Senior Software Engineer, JBoss Performance Team Red Hat ------------------------------------------------------------ Registered Address: RED HAT UK LIMITED, 64 Baker Street, 4th Floor, Paddington. London. United Kingdom W1U 7DF Registered in UK and Wales under Company Registration No. 3798903 Directors: Michael Cunningham (US), Charles Peters (US), Matt Parson (US) and Michael O'Neill(Ireland) On 07/17/2014 06:43 PM, Ludwig Adam wrote: > * Remark* > Resent this message from June 23rd as it did not arrive at the list somehow- please excuse if I was just too dumb to see the message. > > Dear JDBC list, > > we are currently trying to pinpoint some performance issues on our database. > We can identify queries that cause high load on our servers but cannot pinpoint the origin of this query - at the end we only know the output of ps which gives us the client socket port of the query in question, like: > > postgres: CMD > > With a netstat -p | grep we are able to identify the PID of the JVM opening the socket, however in order to further pinpoint this issue we would need to get inside the JVM and determine the Java Thread currently running the query over this socket connection (in our case the java process is a JBoss AS and we would like to get the specific worker(s) issueing the query in question). > > Is there any way to get to the Socket.getLocalPort() of a connection opened, i.e. establish a mapping between a LocalPort and a SQLConnection instance? > > Basically what we want to do is output something like: > > SQLConnection con= pool.getConnection(); // Get connection from pool, includes con.open() > Logger.debug(Thread.currentThread().getName() " has acquired a connection on "+ Mapping.getLocalPortForConnection(con)); > > As we have a central DB management layer we would be able to debug which thread currently occupies a connection on a specific port, thus enabling us to trace the connection to specific thread or at least give us pointers. > > Looking at the source code it seems that the actual Socket connection is done within PGStream. > This socket is declared private and I don't see any debug statements which could give us hints on the local port used. > > Current idea would be now to patch PGStream to add this Mapping. > Perhaps you have a different idea on how to identify the local port or -even better- trace a connection to a specific Java thread. I am certain we are not the only ones with this kind of problem. > > Best regards, > Ludwig > > > > petaFuel GmbH > Ludwig Adam > Geschäftsführer > > Münchner Strasse 4 > 85354 Freising > > Tel.: +49 (0) 8161 4060 - 202 Mobil: +49 (0) 179-22 911 02 > Fax: +49 (0) 8161 4060 - 401 eMail: ludwig.adam@petafuel.de > > Geschäftsführer: Ludwig Adam, Dr. Peter Schönweitz Amtsgericht München, HRB 133773 www.petaFuel.de > > > -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc