--- Gavin King <[EMAIL PROTECTED]> wrote:
> So, let me get this straight:
>
> you, *500 times*
>
> (a) obtain a new JDBC connection
> (b) start a transaction
> (c) do some work
> (d) commit the transaction and close the JDBC
> connection
Not quite that.
I, *500 times*
(a') using the same connection.
(b) start a transaction.
(c) only persist a transient object.
(d) commit the transaction, but do not close the JDBC.
>
> and you are surprised that this is slow??
>
> Why would you not do it all in one transaction?
> Starting and stopping
> transactions is one of _the_ most expensive
> operations you can do with a
> database.
The request is from client-side (an embedded client in
consumer device). The client explicitly specifies the
transaction boudary in its message.
Forget about the 500 transactions. The problem is
this: with 300-500 objects in the session cache, a
single transaction( with an single object inserted)
takes about one second.
I am thinking of this idea: Using a session to load
object only(read-only session). Use a new session for
every transaction just make sure that there is no
object is cached in the session.
Obtaining database connection should not be a problem
since the database connection is pooled at Tomcat
layer.
How do you think of this idea?
Thanks
jason
> jiesheng zhang wrote:
>
> >First I have a source class like this.
> >public class Source
> >{
> > Transaction tx;
> >
> > List pendingRemovedItems;
> > public void beginTransaction()
> > {
> > // here I use ThreadLocal pattern.
> > tx= ThreadState.getSession().beginTransaction();
> > }
> >
> > public void commit()
> > {
> > try
> > {
> > // I need to explicitly delete all items that
> need
> >deletion.
> > for (Iterator iter=
> pendingRemovedItems.iterator();
> > iter.hasNext();
> > )
> > {
> > ThreadState.getSession().delete(iter.next());
> > }
> >
> > tx.commit();
> > logger.info(" db source is commited");
> > pendingRemovedItems.clear();
> > } finally
> > {
> > tx= null;
> > }
> > }
> >
> > // other variables and methods in source.
> >}
> >
> >
> >My application code is like this
> >Source src=...;
> >// when control comes here, there are about 500
> >persistence objects in session.
> >1. src.beginTransaction();
> >2. // here an new transient object is persisted.
> >3. src.commit();
> >
> >The code fragment 1, 2, and 3 will be run 300 to
> 500
> >times.
> >
> >
> >The following is sql code dumped from hibernate.
> That
> >is exactly what I expected. I only show 2 of them.
> The
> >timestamp indicated that each insertion was about
> one
> >second.
> >
> >I am happy to provide any extra information.
> >
> >
> >2003-9-12 12:31:02 ....
> >Info: found cached source
> >Hibernate: select seq_resourceID.nextval from dual
> >Hibernate: insert into contact (luid, dbId, guid,
> >namefirst, namelast, nameother, nameprefix,
> >namesuffix, title, role, orgname, orgunit,
> birthday,
> >url, nickname, timezone, note, binary, categories,
> >class, contactID) values (?, ?, ?, ?, ?, ?, ?, ?,
> ?,
> >?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'd', ?)
> >Hibernate: insert into phonenumber (contactID, num,
> >type) values (?, ?, ?)
> >Hibernate: insert into email (contactID, email,
> type)
> >values (?, ?, ?)
> >2003-9-12 12:31:03 ...
> >Info: db source is commited
> >2003-9-12 12:31:03 ....
> >
> >2003-9-12 12:31:03 ...
> >Info: found cached source
> >Hibernate: select seq_resourceID.nextval from dual
> >Hibernate: insert into contact (luid, dbId, guid,
> >namefirst, namelast, nameother, nameprefix,
> >namesuffix, title, role, orgname, orgunit,
> birthday,
> >url, nickname, timezone, note, binary, categories,
> >class, contactID) values (?, ?, ?, ?, ?, ?, ?, ?,
> ?,
> >?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'd', ?)
> >Hibernate: insert into email (contactID, email,
> type)
> >values (?, ?, ?)
> >Hibernate: insert into phonenumber (contactID, num,
> >type) values (?, ?, ?)
> >2003-9-12 12:31:04 ...
> >Info: db source is commited
> >
> >
> >--- Gavin King <[EMAIL PROTECTED]> wrote:
> >
> >
> >>>the transaction. My code is like this
> >>>
> >>>Tranaction tx=sessiob.beginTransaction();
> >>>foo.setField(newValue);
> >>>tx.commit();
> >>>
> >>>
> >>>
> >>Well, obviously it is not like that, since that
> code
> >>does not
> >>load any objects into the session.
> >>
> >>
> >>
> >>>1. When the commit() is called, will the
> hibernate
> >>>loop through every object in the session
> >>>and check for modification?
> >>>
> >>>
> >>>
> >>Yes.
> >>
> >>
> >>
> >>>2. If it does, is it an expensive operation?
> >>>
> >>>
> >>>
> >>No, not at all.
> >>
> >>
> >>
> >>>Any suggestion to solve the performance
> bottleneck
> >>>
> >>>
> >>in
> >>
> >>
> >>>my situation is really appreacited.
> >>>
> >>>
> >>>
> >>Exactly what does your code *really* look like?
> >>
> >>
> >>
> >>
> >
> >
> >__________________________________
> >Do you Yahoo!?
> >Yahoo! SiteBuilder - Free, easy-to-use web site
> design software
> >http://sitebuilder.yahoo.com
> >
> >
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel