{"id":5838,"date":"2016-10-06T12:45:10","date_gmt":"2016-10-06T17:45:10","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=5838"},"modified":"2016-10-06T13:05:13","modified_gmt":"2016-10-06T18:05:13","slug":"testing-the-overhead-of-creating-connections-vs-using-a-pool-in-weblogic","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2016\/10\/06\/testing-the-overhead-of-creating-connections-vs-using-a-pool-in-weblogic\/","title":{"rendered":"Testing the overhead of creating connections vs using a pool in Weblogic"},"content":{"rendered":"<p>We had a need to understand the overhead of creating connections versus using a pool.  Connection pooling is most beneficial when using very short lived database sessions.  If the associated database request takes longer than a few seconds, we needed to understand what positive impact pooling would have.  In other words, if the request takes a minute, a second to open the connection is less impactful, reducing the benefit of pooling.<\/p>\n<p>Short of running a complete regression test, we came up with what is below to drive conversation&#8230;<\/p>\n<p>Request = http:\/\/host:port\/threadtest.jsp?count=50&#038;pool=false<\/p>\n<p>Drop this in the autodeploy directory\u2026<\/p>\n<pre>\r\n<%@ page import=\"java.sql.*\"%>\r\n<%@ page import=\"javax.sql.*\"%>\r\n<%@ page import=\"javax.naming.*\"%>\r\n\r\n<%\r\nclass TestConns implements Runnable{\r\n  boolean pool;\r\n  weblogic.logging.NonCatalogLogger ncl = new weblogic.logging.NonCatalogLogger(\"Thread Test\");\r\n  TestConns(boolean pool) {\r\n    this.pool = pool;\r\n    Thread t = new Thread(this);\r\n    t.start();\r\n  }\r\n  public void run() {\r\n    ncl.info(\"pool = \" + pool + \" start\");\r\n    try {\r\n      if (this.pool) {\r\n        InitialContext ic = new InitialContext();\r\n        DataSource ds = (DataSource)ic.lookup(\"jdbc\/mdsrep\");\r\n        Connection conn = ds.getConnection();\r\n        conn.close();\r\n      }\r\n      else {\r\n        try {\r\n          Connection conn = DriverManager.getConnection(\"jdbc:oracle:thin:user\/password@dbhost:dbport\/dbservicename.domainname\");\r\n          conn.close();\r\n        }\r\n        catch (Exception e3) {\r\n          ncl.error(e3.getMessage());\r\n          return;\r\n        }\r\n      }\r\n    }\r\n    catch (Exception e) {\r\n      ncl.error(e.getMessage());\r\n    }\r\n    ncl.info(\"pool = \" + pool + \" end\");\r\n  }\r\n}\r\nfor (int i = 1; i <= Integer.parseInt(request.getParameter(\"count\")); i++) {\r\n  TestConns t = new TestConns(Boolean.parseBoolean(request.getParameter(\"pool\")));\r\n}\r\n%>\r\n<\/pre>\n<p>\u2026and you will see log entries such as the following when requesting the page\u2026<\/p>\n<pre>\r\n\/u01\/app\/oracle\/product\/fmw: find . -mmin -1 -type f | xargs egrep 'pool' | grep 12:24 | tail -1\r\n.\/user_projects\/domains\/assortplan\/servers\/AdminServer\/logs\/AdminServer.log00020:####<Oct 6, 2016 12:24:12 PM EDT> <Info> <Thread Test> <host> <AdminServer> <Thread-3432> <<anonymous>> <> <673ae030-d2ab-456d-9ffa-2adfa36aa033-000002c8> <1475771052021> <BEA-000000> <pool = false start>\r\n\/u01\/app\/oracle\/product\/fmw:\r\n<\/pre>\n<p>We saw 247 milliseconds per physical connection&#8230;<\/p>\n<pre>\r\n\/u01\/app\/oracle\/product\/fmw: find . -mmin -30 -type f | xargs egrep '12:24.*Thread Test' | awk '{gsub(\"<\",\"\",$0);gsub(\">\",\"\",$0);if ($20 ~ \"start\") {s[$12]=$15} else {t[$12]=$15}} END {for (i in t) {if (s[i] != \"\") {print i,t[i]-s[i]}}}' | sort | awk '{s+=$2} END {print s\/NR}'\r\n247.537\r\n<\/pre>\n<p>&#8230;and 5 milliseconds from a pool&#8230;<\/p>\n<pre>\r\n\/u01\/app\/oracle\/product\/fmw: find . -mmin -30 -type f | xargs egrep ' 1:24.*Thread Test' | awk '{gsub(\"<\",\"\",$0);gsub(\">\",\"\",$0);if ($20 ~ \"start\") {s[$12]=$15} else {t[$12]=$15}} END {for (i in t) {if (s[i] != \"\") {print i,t[i]-s[i]}}}' | sort | awk '{s+=$2} END {print s\/NR}'\r\n5.58\r\ncmhlcarchapp02:oracle:\/u01\/app\/oracle\/product\/fmw:\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We had a need to understand the overhead of creating connections versus using a pool. Connection pooling is most beneficial when using very short lived database sessions. If the associated database request takes longer than a few seconds, we needed&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2016\/10\/06\/testing-the-overhead-of-creating-connections-vs-using-a-pool-in-weblogic\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[48,77,52],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5838"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=5838"}],"version-history":[{"count":6,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5838\/revisions"}],"predecessor-version":[{"id":5845,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5838\/revisions\/5845"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=5838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=5838"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=5838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}