The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Java Web Application,How to make it scalable.

  I am making web application that uses jsp/servlets( at the front end )and MySQL database.It is deployed on tomcat.There are a lot inserts that i have to perform.Currently what i have done is,i have written a helper class where i invoke a single method which does all the inserts.I have marked this method as 'Synchronized'.
I think for a limited number of users this approach might work fine but what if the number of users accessing the web apps is large.Can you please suggest some better approach to handle scalability and also transactions.
I thought of using JTA but i think with tomcat we need to download some transaction manager to use JTA.
Rajat Mehta Send private email
Saturday, October 15, 2005
Also i would like to add that i am not using EJBs and i am not planning to use them either.
Rajat Mehta Send private email
Saturday, October 15, 2005
Why did you synchronize the insert?
Saturday, October 15, 2005
As Matt suggests, don't synchronize. The preferred method to sequencing servlet requests is implementing SingleThreadModel. That is a REALLY expensive thing to do.

For performance, you may look at prevayler
Dino Send private email
Saturday, October 15, 2005
Just guessing, but perhaps you should be using database transactions instead.

I'm assuming you synchronize because multiple tables are being updated.

MySQL has supported transactions for quite a while. You must have the tables in InnoDB format.

Which is why Oracle's purchase of Inno has caused so much discussion.
Shouldn't it be easier?
Sunday, October 16, 2005
And you should try to make the primary keys on your tables such that doing multiple inserts at a time don't cause problems (if this is indeed the case).
Sunday, October 16, 2005
"Can you please suggest some better approach to handle scalability and also transactions."

InnoDB table type as mentioned. Let the database handle commit/rollback.
MBJ Send private email
Monday, October 17, 2005
Thanks a lot for the response.I am planning to use Prevayler or CementJ that might solve my problem,otherwise i will use transactions at the database level only.
Monday, October 17, 2005
Are you using connection pooling or does your singleton have a single jdbc connection which you are using for all the threads - and hence needing the sync?

As mentioned what you want to do is use the databases transaction support to get your ACIDity. MySql InnoDb supports various isolation levels so check the docs to determine which you want and how to set it.

For the Java side set up a connection pool (for example commons-dbcp ( from which code that needs to use the db can grab a connection as needed. This way you can use the databases support for concurrent access which should be a lot more efficient than syncronizing around db access.
Monday, October 17, 2005
Also, Tomcat 5 and later (maybe earlier too, but I haven't used them) use DBCP automagically when the driver supports pooling.  It's very simple to set up.
Matt Brown
Monday, October 17, 2005
Just a side note... do you really need transaction support? In many cases you do but in some cases it is overkill and can further hurt performance. Careful design of your insert statements and your DB primary keys may allow you to perform your inserts without synchronization or transactions.

You would be the only one who really knows the answer to this. I'm NOT saying that transaction support is a huge performance killer. Also, data integrity is always critical. However, I've seen many developers just default to using transactions when they really didn't end up needing them. Just a thought...
Monday, October 17, 2005
I agree with you Matt.Actually what i was thinking is that 'since there are a lot of inserts into different tables at a time,so i should use transactions'.But i think it depends on the number of concurrent requests at a time.I don't think my application will have a lot of concurrent requests at the same time,currently.For scalability and all i think i will try to plug this transactional think later.
I am using the DBCP datasource on tomcat and connection pooling is working fine for me now.
Wednesday, October 19, 2005

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz