Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Visual J# / March 2005

Tip: Looking for answers? Try searching our database.

simple SQL select statement 10x faster in J++ than in J#... why?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DotNetDev8080 - 28 Feb 2005 19:17 GMT
I am seeing vastly different SQL performance numbers in a ported J# project
vs. my old J++ code base.  The problem seems to be ResultSet.getString() --
.getInteger() performs just fine.  I saw some posts about setting
sendStringParametersAsUnicode=false but that did not help in my case.

Here are the results of a test against the standard SQL Server Northwind
database:
--------------------------------------------------
J#
execute query took - 0.094 seconds
processing result set took - 0.75 seconds

J++
execute query took - 0.016 seconds
processing result set took - 0.078 seconds
---------------------------------------------------

My (very simple) test case is below.  It goes against the Northwind database
so it is easy to try out, and it compiles as is in both J# and J++.  Am I
missing a config parameter or something?

Thanks,
-B

package UnitTests;

import java.sql.*;
import java.util.*;

/**
* Summary description for DBPerformanceTest.
*/
public class DBPerformanceTest
{
    public static final String sql = "select EmployeeID, ShipName, ShipAddress
from Orders";

    private Connection connection = null;

    public static void main(String[] args)
    {
        try
        {
            DBPerformanceTest test = new DBPerformanceTest();
            test.Init();
            test.runPerformanceTest();
            Thread.sleep(10000);
        }
        catch(Throwable e)
        {
            e.printStackTrace();
        }
        System.exit(0);
    }

    public DBPerformanceTest()
    {
    }

    public void Init() throws Exception
    {
        synchronized(this)
        {
            if(connection == null)
            {
                Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver");
                String url = "jdbc:odbc:Driver={SQL
Server};Server=(local);UID=sa;PWD=;Database=northwind;sendStringParametersAsUnicode=false";
                Properties p = new Properties();
                p.put("selectMethod", "cursor");
                connection = DriverManager.getConnection(url, p);
                connection.setAutoCommit(false);
                connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
   
            }
        }
    }

    public void runPerformanceTest() throws Exception
    {
        this.getInfoViaJDBC();
    }

    public void getInfoViaJDBC() throws Exception
    {
        Timer timer;
        double javaTime;
        String message;

        timer = new Timer();
        timer.start();
        Statement st = connection.createStatement();
        ResultSet r = st.executeQuery(sql);
        timer.stop();
        javaTime = timer.value();

        message = "execute query took - "+javaTime+" seconds";
        System.out.println(message);

        timer = new Timer();
        timer.start();
        while (r.next())
        {
             Integer i = new Integer(r.getInt(1));
             String s1 = r.getString(2);
             String s2 = r.getString(3);
        }

        r.close();
        st.close();
        timer.stop();
        javaTime = timer.value();
        message = "processing result set took - "+javaTime+" seconds";
        System.out.println(message);
    }
}

------------------------------------------------
Timer class
-------------------------------------------------

package UnitTests;

import java.io.PrintWriter;
import java.text.*;

public class Timer
{
   static String id = "@(#) $Id: Timer.java,v 1.2 2002/12/27 20:37:48 hook
Exp $";

    private long begin;
    private long end;
    DecimalFormat df;

    public Timer()
    {
        super();
        begin = 0;
        end = 0;
        df = new DecimalFormat("00.##");
    }

    long now()
    {
        return System.currentTimeMillis();
    }
    public void start()
    {
        begin = now();
    }

    public void stop()
    {
        end = now();
    }

    public double value()
    {
        return ((end - begin)/1000.000);
    }

    public String toString()
    {
        double secs = this.value();
        double mins = Math.floor(secs / 60.0);
        double hours = Math.floor(mins / 60.0);
        secs = secs - (60.0 * mins);
        mins = mins - (60.0 * hours);
        return (df.format(hours) + ":" + df.format(mins) + ":" + df.format(secs));
    }
    public void print()
    {
        System.out.println(toString());
    }
    public void print(PrintWriter writer)
    {
        writer.println(toString());
    }

}
Lars-Inge T?nnessen [VJ# MVP] - 01 Mar 2005 19:37 GMT
I don't know why, but I have seen these performance issues before.

It could be the string processing (it's slow in .NET 1.x). The good news is
that .NET 2.0 has a huge performance improvement in J#. Download the Visual
Studio 2005 Express beta and give it a try. It's very stable.

http://lab.msdn.microsoft.com/express/vjsharp/default.aspx

Regards,
Lars-Inge T?nnessen
DotNetDev8080 - 03 Mar 2005 00:21 GMT
Well, I'll be happy to use 2005 when it comes out in 6 months, but this is
not going to solve my problem for now, because I can't ship Beta code to my
customers.  Also, it seems to me like this is a J#-specific problem, not a
.Net one, because J# Sql is 20x slower than if you use the .Net Sql classes.

So, is there any way to ship a performant J# database-driven application
before 2005 ships using J# sql classes?  Or do I have to write J# sql - to -
.Net sql wrappers (quite a lot of development work, and testing) so that I
can ship my app?  My users are not going to stand for a 10x reduction in
database performance.  

"Lars-Inge Tønnessen [VJ# MVP]" wrote:

> I don't know why, but I have seen these performance issues before.
>
[quoted text clipped - 6 lines]
> Regards,
> Lars-Inge Tønnessen

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.