通过DriverManager.getConnection连接到Informix的速度很慢 [英] Connecting to Informix via DriverManager.getConnection is slow

查看:512
本文介绍了通过DriverManager.getConnection连接到Informix的速度很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JDBC通过DriverManager.getConnection method连接到Informix实例,但是我遇到了问题.

I am using JDBC to connect to an Informix instance via the DriverManager.getConnection method, but I have problems.

DriverManager.getConnection需要很长时间才能与Informix建立连接.我正在尝试解决此问题,但到目前为止尚未成功.

DriverManager.getConnection takes a long time to establish a connection with Informix. I'm trying to solve this problem, but have not been successful so far.

如何解决这个问题?

推荐答案

您可以编写简单的测试,以显示连接数据库需要多长时间. 对于这些事情,我喜欢可以与JDBC一起使用的Jython,它可以与本机JDBC驱动程序一起使用,并且通过JDBC-ODBC桥可以与ODBC驱动程序一起使用.当然,您必须首先配置这种ODBC连接.

You can write simple test that shows how long it takes to connect to database. For such things I like Jython that can work with JDBC, which can work with native JDBC drivers and via JDBC-ODBC bridge can work with ODBC driver. Of course you must first configure such ODBC connection.

这是显示此类时间的测试程序:

This is test program that shows such times:

import sys
import traceback
import time

from java.sql import DriverManager
from java.lang import Class

Class.forName("com.informix.jdbc.IfxDriver")

def test_conn(db_url, usr, passwd):
    try:
        t0 = time.time()
        try:
            db = DriverManager.getConnection(db_url, usr, passwd)
            t2 = time.time()
            print('%s' % (db_url))
            print('%s, connection time %.03f [s]\n' % (db, (t2-t0)))
        finally:
            db.close()
    except:
        print("there were errors!")
        s = traceback.format_exc()
        sys.stderr.write("%s\n" % (s))


def main():
    for _ in range(5):
        test_conn('jdbc:informix-sqli://169.0.5.10:9088/test:informixserver=ol_t1;', 'user', 'passwd')
        test_conn('jdbc:odbc:ifx_test', 'user', 'passwd')

main()

我的机器上的结果表明,JDBC的连接速度比JDBC-ODBC桥更快(您必须知道该桥会增加一些本机应用程序不必要的时间).我的测试也在Windows上运行,其中time.time()的最小分辨率可能约为15毫秒.我的结果:

Results on my machine shows that JDBC is faster in connecting then JDBC-ODBC bridge (you must know that bridge adds some time that is not necessary with native applications). Also my test is run on Windows where minimal resolution of time.time() is probably ~15 ms. My results:

jdbc:informix-sqli://169.0.5.10...
com.informix.jdbc.IfxSqliConnect@1658cfb, connection time 0.015 [s]

jdbc:odbc:test
sun.jdbc.odbc.JdbcOdbcConnection@ad75b, connection time 0.047 [s]

当然,使用此程序,您可以测试相同的驱动程序,但可以在不同服务器上测试数据库.

Of course with this program you can test the same driver but with databases on different servers.

这篇关于通过DriverManager.getConnection连接到Informix的速度很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆