Re: JAVA vs PERL : PERL wins to postgreSQL
От | Barry Lind |
---|---|
Тема | Re: JAVA vs PERL : PERL wins to postgreSQL |
Дата | |
Msg-id | 3B9505E0.9070001@xythos.com обсуждение исходный текст |
Ответ на | JAVA vs PERL : PERL wins to postgreSQL (andy <andy@exkom.co.za>) |
Список | pgsql-jdbc |
Andy, Thanks for the code. In looking at this there are two things that come to mind: 1) You probably should be running vacuum after the delete to clean up the table, but on a table this small, I doubt it will make any real difference. 2) Why have you set autocommit on? This should be much faster with autocommit off. Actually I just did a quick test of the two changes I mentioned above. The first (vacuum) doesn't make any noticable difference, however turning autocommit off causes the timings on my machine to go from 14 seconds to 6 seconds. Better than 50% improvement. thanks, --Barry andy wrote: > To all those who responded , > Thanks for your response, > > I have attached the test programs that I used in the form of text files. The > contents should be self evident. Please have a look and comment. > > I used j2sdk1.3.1 down load to linux machine from sun.com as my java platform > and > And perl, v5.6.0 built for i386-linux. > The PostgreSQL driver for perl came from www.perl.org > The postgreSQL driver in jdbc7.0-1.2.jar > > > Barry Lind wrote: > > >>Andy, >> >>I would be interesting in knowing what version you did this test on, >>what platform, and most importantly which JDK (and if the Sun JDK which >>JVM: classic, hotspot client, hotspot server). >> >>thanks, >>--Barry >> >>andy wrote: >> >>>Hi, >>> >>>I ran a few bench marks on JAVA writing to a postgreSQL table using and >>>found that for the same number of records added to the table as a >>>similar PERL routine the following results : >>> PERL 39 seconds : JAVA 45 Seconds. >>>In a similar experiment where PERL and JAVA did treir output to the >>>screen and not to a table, >>> >>>JAVA took 3 seconds and PERL 310 Seconds. >>>My conclusion is that the database driver to postgreSQL is still far >>>from efficient in the JAVA implementation. >>> >>>Both tests were run on the same computer. >>> >>>I would appreciate your comments and suggestions. >>>Andy Sewell >>> >>> >>>---------------------------(end of broadcast)--------------------------- >>>TIP 5: Have you checked our extensive FAQ? >>> >>>http://www.postgresql.org/users-lounge/docs/faq.html >>> >>> >>> >>> >>>------------------------------------------------------------------------ >>> >>>/* >>> Java bench mark against perl count to 100 000 000 >>>*/ >>>import java.io.*; >>>import java.util.*; >>> >>>public class lp{ >>> >>> public lp() throws ClassNotFoundException, FileNotFoundException, IOException >>> { >>> int last = 1000; >>> >>> GregorianCalendar day = new GregorianCalendar(); >>> String time = day.getTime().toString(); >>> int k=0; >>> for (int i=0; i<last ; i++) { >>> for (int p=0; p<last ; p++) {k=1+p;System.out.println(k);} >>> } >>> >>> GregorianCalendar day1 = new GregorianCalendar(); >>> String time2 = day1.getTime().toString(); >>> System.out.println(time); >>> System.out.println(time2 + "\n" + k); >>> >>> >>> } >>> >>>public static void main(String[] args) { >>> try { >>> lp test = new lp(); >>> } >>> catch (Exception ex) { >>> System.err.println("Exception :" + ex); >>> ex.printStackTrace(); >>> } >>>} >>>} >>> >>> >>> >>>------------------------------------------------------------------------ >>> >>>/* >>> Java equivalent >>>*/ >>>import java.io.*; >>>import java.sql.*; >>>import java.util.*; >>> >>>public class pg{ >>> Connection conn; >>> Statement stmt; >>> >>> public pg() throws ClassNotFoundException, FileNotFoundException, IOException, SQLException >>> { >>> Class.forName("org.postgresql.Driver"); >>> conn = DriverManager.getConnection("jdbc:postgresql:exkom", "andy", ""); >>> conn.setAutoCommit(true); >>> stmt = conn.createStatement(); >>> int last = 10000; >>> int res = stmt.executeUpdate("delete from junk"); >>> >>> GregorianCalendar day = new GregorianCalendar(); >>> String time = day.getTime().toString(); >>> >>> for (int i=0; i<last ; i++) { >>> // try { >>> res = stmt.executeUpdate("insert into junk values(" + i + ")"); >>> >>> // } catch (SQLException e) { >>> // System.out.println(e); >>> // } >>> } >>> >>> GregorianCalendar day1 = new GregorianCalendar(); >>> String time2 = day1.getTime().toString(); >>>// String time3 = day.getTime().toString(); >>> System.out.println(time); >>> System.out.println(time2); >>>// System.out.println(time3); >>> >>>// res.close(); >>> stmt.close(); >>> conn.close(); >>> >>> >>> } >>> >>>public static void main(String[] args) { >>> try { >>> pg test = new pg(); >>> } >>> catch (Exception ex) { >>> System.err.println("Exception :" + ex); >>> ex.printStackTrace(); >>> } >>>} >>>} >>> >>>/** >>> >>> >>>$conn = Pg::connectdb("dbname=exkom"); >>>die $conn->errorMessage unless PGRES_CONNECTION_OK eq $conn->status; >>> >>># print "Enter a state code :"; >>># $state_code = <STDIN>; >>> >>># chomp $state_code; >>>$result = $conn->exec("delete from junk"); >>>$end = 10000; >>> >>>$t0 = new Benchmark; >>> >>>for ($i=1; $i < $end; $i++) { >>> $result = $conn->exec("insert into junk values($i)"); >>>} >>> >>>$t1 = new Benchmark; >>>$td = timediff($t1, $t0); >>>print " the $end records took :", timestr($td) , "\n" >>>**/ >>> >>> >>>------------------------------------------------------------------------ >>> >>> >>>---------------------------(end of broadcast)--------------------------- >>>TIP 3: if posting/reading through Usenet, please send an appropriate >>>subscribe-nomail command to majordomo@postgresql.org so that your >>>message can get through to the mailing list cleanly >>> >>> lp.java >>> >>> Content-Type: >>> >>> text/plain >>> Content-Encoding: >>> >>> 7bit >>> >>> >>> ------------------------------------------------------------------------ >>> lp.pl >>> >>> Content-Type: >>> >>> application/x-perl >>> Content-Encoding: >>> >>> 7bit >>> >>> >>> ------------------------------------------------------------------------ >>> pg.java >>> >>> Content-Type: >>> >>> text/plain >>> Content-Encoding: >>> >>> 7bit >>> >>> >>> ------------------------------------------------------------------------ >>> pg.pl >>> >>> Content-Type: >>> >>> application/x-perl >>> Content-Encoding: >>> >>> 7bit >>> >>> >>> ------------------------------------------------------------------------ >>> Part 1.6 >>> >>> Content-Type: >>> >>> text/plain >>> Content-Encoding: >>> >>> binary >>> >>>
В списке pgsql-jdbc по дате отправления:
Предыдущее
От: "chris markiewicz"Дата:
Сообщение: error - NOTICE: current transaction is aborted, queries ignored until end of transaction block