[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql-java
Subject:    Re: Too slow when using useUnicode=true&characterEncoding=gb2312
From:       Huang wen hui <hwh () gddsn ! org ! cn>
Date:       2003-04-23 3:15:16
[Download RAW message or body]

Mark Matthews wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Huang wen hui wrote:
>| hi,
>| I am using Mysql 3.23.56 server+ mysql-connector-java-2.04(or 3.07).
>| I found that my program will run too slow when using
>| useUnicode=true&characterEncoding=gb2312
>| but if I comment out the line "String locID = getLocID(buf); //run
>| faster when remove it " or
>| comment out "rs.getString("net"); //run faster when remove it", the
>| program will fast
>| again. Please see the following attached code.>
>| I really need to use "useUnicode=true&characterEncoding=gb2312", How to
>| solve this problem?
>
>Unfortunately, if you're using a multi-byte character set like GB2312,
>your Strings are going to have to go through Sun's character conversion
>code, which is not fast, it's can be around 10 times slower than doing
>it by hand (which is what is done for single-byte character sets, but it
>can't be done for multibyte character sets).
>
>| Can I configurate mysql server or Do I need some tips for programing ?
>
>You don't say what JVM you're using, but newer JVMs (like 1.4.0) are
>quite a bit faster at this character conversion.
>
I think I found the problem. I use two different encoding  character 
set  in while loop. 
"String locID = getLocID(buf)" use default "eucCN" and
"rs.getString("net")" use "gb2312".  Thanks anyway!

--hwh

>
>|
>| --hwh
>|
>|
>| mysql> explain waveform;
>|
>+---------------+-----------------------+------+-----+---------------------+-------+
>| | Field | Type | Null | Key | Default | Extra |
>|
>+---------------+-----------------------+------+-----+---------------------+-------+
>| | event_id | varchar(40) | | MUL | | |
>| | net | char(2) | | | | |
>| | sta | varchar(5) | | | | |
>| | loc_id | char(2) | | | | |
>| | chan | char(3) | | | | |
>| | serial_number | mediumint(8) unsigned | YES | | NULL | |
>| | srate | double(10,5) | | | 0.00000 | |
>| | nsamples | smallint(5) unsigned | YES | | NULL | |
>| | start_time | datetime | | MUL | 0000-00-00 00:00:00 | |
>| | start_time_ns | int(11) | YES | | NULL | |
>| | end_time | datetime | | MUL | 0000-00-00 00:00:00 | |
>| | end_time_ns | int(11) | YES | | NULL | |
>| | waveform | blob | | | | |
>|
>+---------------+-----------------------+------+-----+---------------------+-------+
>|
>| Test program output:
>| 1. use "useUnicode=true&characterEncoding"
>| java DatabaseEvt
>| DECODE MiniSeed ...
>| DECODE MiniSeed elapse time: 54764 ms.
>| Open DB Event OK!
>|
>| 2. remove "useUnicode=true&characterEncoding" or
>| remove "String locID = getLocID(buf);" or
>| remove "rs.getString("net");"
>|
>| java DatabaseEvt
>| DECODE MiniSeed ...
>| DECODE MiniSeed elapse time: 2312 ms.
>| Open DB Event OK!
>|
>|
>|
>|
>| ------------------
>| import java.net.*;
>| import java.sql.*;
>| import java.util.*;
>| import java.text.SimpleDateFormat;
>|
>|
>| public class DatabaseEvt {
>|
>| private Connection wfdbConn = null;
>| private java.util.Date beg = null;
>| private java.util.Date end = null;
>|
>| public DatabaseEvt(Connection wfdbConn) {
>| this.wfdbConn = wfdbConn;
>| }
>|
>| public void setTimeSpan(java.util.Date beg, java.util.Date end) {
>| this.beg = beg;
>| this.end = end;
>| }
>|
>| public boolean readEvtFile() {
>| System.err.println("DECODE MiniSeed ...");
>| long now_ms = new java.util.Date().getTime();
>|
>| int nChannel = 0;
>| SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
>| sdf.setTimeZone(TimeZone.getTimeZone("GMT+08"));
>| Statement stmt = null;
>| ResultSet rs = null;
>| byte[]buf = null;
>|
>| try {
>| stmt = wfdbConn.createStatement();
>| String sqlStr;
>| String start_time = sdf.format(beg);
>| String end_time = sdf.format(end);
>|
>| sqlStr =
>| "select * from waveform where start_time >= '" + start_time +
>| "' AND start_time <= '" + end_time +
>| "' order by net, sta, loc_id, chan, start_time, start_time_ns";
>| rs = stmt.executeQuery(sqlStr);
>|
>| while(rs.next()){
>| Blob waveform = rs.getBlob("waveform");
>| int len = (int)waveform.length();
>| buf = waveform.getBytes(1, len);
>| String locID = getLocID(buf); //run faster when remove it
>| rs.getString("net"); //run faster when remove it
>| }
>|
>| //debug
>| long n_now_ms = new java.util.Date().getTime();
>| System.err.println("DECODE MiniSeed elapse time: "+(n_now_ms-now_ms) +"
>| ms.");
>|
>| rs.close();
>| stmt.close();
>| }
>| catch(SQLException sqlEx) {
>| sqlEx.printStackTrace();
>| return false;
>| }
>|
>| return true;
>| }
>|
>| public String getLocID(byte[] buf) {
>| return (new String(buf, 13, 2)).trim();
>| }
>|
>|
>| public static void main(String[] args) throws Exception {
>| Class.forName("com.mysql.jdbc.Driver").newInstance();
>| java.sql.Connection conn;
>| conn = DriverManager.getConnection(
>|
>"jdbc:mysql://192.168.168.135/rts?useUnicode=true&characterEncoding=gb2312&user=rts&password=rts");
>| DatabaseEvt ded = null;
>| ded = new DatabaseEvt(conn);
>|
>| SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
>| String startTime = "2003-04-21 11:00:00";
>| String endTime = "2003-04-21 12:0:00";
>|
>| java.util.Date beg = sdf.parse(startTime);
>| java.util.Date end = sdf.parse(endTime);
>|
>| ded.setTimeSpan(beg, end);
>| if(ded.readEvtFile())
>| System.err.println("Open DB Event OK!");
>| }
>| }
>|
>|
>|
>|
>
>
>- --
>For technical support contracts, visit https://order.mysql.com/?ref=mmma
>
>~    __  ___     ___ ____  __
>~   /  |/  /_ __/ __/ __ \/ /  Mark Matthews <mark@mysql.com>
>~  / /|_/ / // /\ \/ /_/ / /__ MySQL AB, Full-Time Developer - JDBC/Java
>~ /_/  /_/\_, /___/\___\_\___/ Flossmoor (Chicago), IL USA
>~        <___/ www.mysql.com
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.2.1 (MingW32)
>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
>iD8DBQE+pUMdtvXNTca6JD8RAv2iAJ9WdrgRo5qW/edzdm897zRaZrVjTACePdOf
>gqbOHYbWPFLEt0uuRyec168=
>=01gI
>-----END PGP SIGNATURE-----
>
>
>
>  
>



-- 
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe:    http://lists.mysql.com/java?unsub=mysql-java@progressive-comp.com

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic