[PERFORM] How to speed-up inserts with jdbc

2004-11-10 Thread Michael Kleiser
Im PostgreSQL 7.2.2 / Linux 2.4.27  dual-processor Pentium III 900MHz,
we have this table:
create table testtable (id SERIAL PRIMARY KEY, coni VARCHAR(255), date 
TIMESTAMP, direction VARCHAR(255), partner VARCHAR(255), type VARCHAR(255), 
block VARCHAR(255) );
We using Java with JDBC-driver pg72jdbc2.jar
our Java-testgrogram is :
public class Stresser implements Runnable {
public void run() {
System.out.println(- start);
try {
	
	Class.forName(org.postgresql.Driver);
	Connection con = DriverManager.getConnection(jdbc:postgresql://+prop.getProperty(host)+:+prop.getProperty(port)+/+prop.getProperty(dbname), prop.getProperty(user), 
prop.getProperty(pwd));
	con.setAutoCommit(true);
	Statement  st = con.createStatement();
	java.sql.Timestamp datum = new java.sql.Timestamp(new Date().getTime());
	Date start = new Date();
	System.out.println(start);
	for (int i=0; i100; ++i) {
	st.executeUpdate(insert into history(uuid,coni,date,direction,partner,type) values('uuid','content','+datum+','dir','partner','type'));
	}
	Date end = new Date();
	System.out.println(end);
	con.close();
} catch (Exception e) {
System.out.println(Exception!);
e.printStackTrace();
}
System.out.println(- ende);
}

public static void main(String[] args) {
for (int i=0; i10; ++i) {
Stresser s = new Stresser();
Thread t = new Thread(s);
t.start();
}
}
}
It is trunning in in 10 Threads. Each thread makes 100 Inserts:
For the 1000 Inserts (10 threads a 100 inserts)
we need 8 seconds.
That's 125 Insets / Seconds.
How could we make it faster ?
Inserting 1000 rows via  INSERT AS SELECT is much faster.
regards
  Michael
---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [PERFORM] Data Warehouse Reevaluation - MySQL vs Postgres --

2004-09-14 Thread Michael Kleiser
What MySQl-table-type did you use?
Was it MyISAM which don't supports transactions ?
Yes I read about that bulk-inserts with this table-type are very fast.
In Data Warehouse one often don't need transactions.
Leeuw van der, Tim schrieb:
-Original Message-
From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] Behalf Of Steinar H. 
Gunderson
Sent: Tuesday, September 14, 2004 3:33 PM
To: PostgreSQL Performance List
Subject: Re: [PERFORM] Data Warehouse Reevaluation - MySQL vs Postgres --

  On Tue, Sep 14, 2004 at 02:42:20PM +0200, Leeuw van der, Tim wrote:
   - PostgreSQL 7.3 running on CYGWIN with cygipc daemon
 
  Isn't this doomed to kill your performance anyhow?
Yes and no, therefore I mentioned it explicitly as one of the caveats. 
When doing selects I could get performance very comparable to MySQL, so 
I don't want to blame poor insert-performance on cygwin/cygipc per se.
I'm not working on this app. anymore and don't have a working 
test-environment for it anymore so I cannot retest now with more recent 
versions.

regards,
--Tim
 
  /* Steinar */
  --
  Homepage: http://www.sesse.net/

---(end of broadcast)---
TIP 8: explain analyze is your friend
---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])
---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
 subscribe-nomail command to [EMAIL PROTECTED] so that your
 message can get through to the mailing list cleanly