Google Gears vs. JDBC (performance)

This year I’m teaching a course in the Hebrew University (advanced Internet technologies), I’m currently guiding one of my students, we are designing a web framework that heavily uses the abilities of Google Gears, I will elaborate about this project on a future post.

I must share with you a performance testing that we have been doing in order to proof the concept of client side database efficiency.

As I belong to the Java/J2EE school, I compared a JDBC method to a Javascript function that uses the Gears API (mainly the Database object)

My test case was simple, creating a new simple table with one column(int), inserting N rows(increasing number from 0 to N-1), selecting * from that table and finally iterating the result one by one.

In order to isolate the database connectivity problem from few multithreading issues I have used IE8 to test the javascript code ( and not chrome or FireFox).

The results are unbelievable:

The X axis represent N (the number of rows I have inserted), the Y axis represents time(ms).

Gears is working faster then JDBC!

Few issues I had:

1) This is happening only when I wrap the gears code with a transaction ( I think it’s not an issue due to the nature of a client side programming. no more than one concurrent user), (thanks to the Gears team for helping me here..)

2) Of course you can claim that JDBC is just an underneath layer and it can be work under a 2nd level cache layer, well we can defiantly implement a 2nd level cache for Gears as well as part of our framework 😉

3) Why IE8?  Chrome and maybe firefox 3.5 are working differently with threads and I did not want to add code that deals with threads (WorkerPool)

4) I have used the MySql database to test the JDBC code.

5) Gears code:

function db(numOfRows) {
var currentTime = new Date().getTime();
var db = google.gears.factory.create(“beta.database”);“gearsDb”);
db.execute(‘BEGIN’);//start tx
db.execute(“delete from data”);
db.execute(“create table if not exists data (rowId int)”);
db.execute(“insert into data values (“+i+”)”);
var rs = db.execute(“select rowId from data”);
var val = 0;
while (rs.isValidRow()){
val = rs.field(0);;
var currentTime2 = new Date().getTime();
currentTime2 -=currentTime;
document.write(currentTime2+”,”+numOfRows+ “<BR/>”);

6) JDBC code:

long time = System.currentTimeMillis();
DriverManager.registerDriver(new Driver());
Connection con = DriverManager.getConnection(“jdbc:mysql://myLab:3306/jdbcPerTest”, “root”, “pass”);
PreparedStatement stmt = con.prepareStatement(“insert into data values (?)”)
stmt.execute(“delete from data”);
for(int i =0 ;i<param;i++){
stmt.setInt(1, i);

ResultSet rset = stmt.executeQuery(“select * from data”);
int result = 0;
while ( {
result = rset.getInt(1);
long time2 = System.currentTimeMillis();

System.out.println(param+”,”+(time2 – time));


For me such a results are a begining of an era, yet post factum those results are obvious..

If you had like to join such a web framework development please let me know..


6 thoughts on “Google Gears vs. JDBC (performance)

  1. Well your java code
    1) Does not close ResultSet!
    2) Does not use PreparedStatement
    3) I don’t know why you’re messing with transaction in scenario where autocommit is sufficient

  2. I actually had the close() calls in the original code which doesn’t really matter because it’s after the last System.currentTimeMillis()

    I changed the Statement to PreparedStatement which obviously changed the numbers, yet it was negligible.( when first read your comment, I thought it will be significant..)

    I used a transaction in the JDBC method in order to make it similar to the Gears code + the transaction made it run faster(~X2).

    I don’t think I will change the MySQL driver to SQLite because it doesn’t make sense for a web app to use SQLite on the server side.
    It doesn’t make sense to use MySQL on the client side as well.

    thanks for all the feedback, I do appreciate it!

  3. This is not comparing Gears and JDBC

    This is testing an embedded SQL server with a mysql instance over a socket

    Stop and think for a moment… Does it still surprise you?

  4. I agree with bloid. Gears has a local db that it’s using. JDBC is connecting to db via a socket. A local db has to be faster than accessing a db through a network.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s