TDEngine和MySQL单表100万数据查询性能比较

TDEngine表结构

 

 

SQL语句

 

 

程序

package com.test.df.tdengine.intd.jianshaozibiao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.util.Random;

public class Yace2 {

    public static void main(String[] args) {
        final int threadCnt = Integer.parseInt(args[0]);
        
        for(int i=0;i<threadCnt;i++) {
            
            final int tt = i;
            
            new Thread() {
                
                public void run() {
                    
                    try {
                        Connection conn = TestSensorImport6.getConn();
                        
                        Random rand = new Random();
                        
                            
                        while(true) {
//                            StringBuilder sql = new StringBuilder("select count(*) from t1 where p1>0.4 group by type");
                            StringBuilder sql = new StringBuilder("select count(*) from t1  group by type");

                            Date d1 = new Date();
                            
                            Statement stmt = conn.createStatement();
                            
                            ResultSet rs = stmt.executeQuery(sql.toString());
                            
                            while (rs.next()) {
                                rs.getString(1);
                            }
                            System.out.println(Thread.currentThread()+":"+d1+":"+new Date());
                            rs.close();
                            stmt.close();
                            
                        }
                    } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    
                };
                
            }.start();
        }

    }

}

 

10个并发,查询时间10秒左右

Thread[Thread-3,5,main]:Mon Nov 08 18:59:06 CST 2021:Mon Nov 08 18:59:14 CST 2021
Thread[Thread-6,5,main]:Mon Nov 08 18:59:06 CST 2021:Mon Nov 08 18:59:14 CST 2021
Thread[Thread-0,5,main]:Mon Nov 08 18:59:07 CST 2021:Mon Nov 08 18:59:15 CST 2021
Thread[Thread-7,5,main]:Mon Nov 08 18:59:08 CST 2021:Mon Nov 08 18:59:16 CST 2021
Thread[Thread-4,5,main]:Mon Nov 08 18:59:09 CST 2021:Mon Nov 08 18:59:17 CST 2021
Thread[Thread-9,5,main]:Mon Nov 08 18:59:10 CST 2021:Mon Nov 08 18:59:18 CST 2021
Thread[Thread-5,5,main]:Mon Nov 08 18:59:11 CST 2021:Mon Nov 08 18:59:19 CST 2021
Thread[Thread-8,5,main]:Mon Nov 08 18:59:12 CST 2021:Mon Nov 08 18:59:19 CST 2021
Thread[Thread-1,5,main]:Mon Nov 08 18:59:12 CST 2021:Mon Nov 08 18:59:20 CST 2021
Thread[Thread-2,5,main]:Mon Nov 08 18:59:13 CST 2021:Mon Nov 08 18:59:21 CST 2021
Thread[Thread-3,5,main]:Mon Nov 08 18:59:14 CST 2021:Mon Nov 08 18:59:22 CST 2021
Thread[Thread-6,5,main]:Mon Nov 08 18:59:14 CST 2021:Mon Nov 08 18:59:23 CST 2021
Thread[Thread-0,5,main]:Mon Nov 08 18:59:15 CST 2021:Mon Nov 08 18:59:23 CST 2021
Thread[Thread-7,5,main]:Mon Nov 08 18:59:16 CST 2021:Mon Nov 08 18:59:25 CST 2021
Thread[Thread-4,5,main]:Mon Nov 08 18:59:17 CST 2021:Mon Nov 08 18:59:25 CST 2021
Thread[Thread-9,5,main]:Mon Nov 08 18:59:18 CST 2021:Mon Nov 08 18:59:26 CST 2021
Thread[Thread-5,5,main]:Mon Nov 08 18:59:19 CST 2021:Mon Nov 08 18:59:27 CST 2021
Thread[Thread-8,5,main]:Mon Nov 08 18:59:19 CST 2021:Mon Nov 08 18:59:28 CST 2021

 

MySQL表结构

 

 

SQL语句

 

 

程序

package org.mysql;

import java.sql.*;
import java.util.Date;
import java.util.Random;

public class Test5 {

    public static void main(String[] args)  throws Exception{

        for(int j=1;j<=10;j++) {

            final int tt = j;

            new Thread(){

                @Override
                public void run() {



                    try {
                        Connection con = null;

                        PreparedStatement ps = null;
//        String JDBC_DRIVER = "com.mysql.jdbc.Driver";
                        String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";

                        String CONNECTION_URL = "jdbc:mysql://192.168.7.193:3306/test?rewriteBatchedStatements=true";

                        Class.forName(JDBC_DRIVER);
                        con = DriverManager.getConnection(CONNECTION_URL, "root", "123456");

                        String sql = " select a.type1,c1,c2 from (  select type1,count(*) as c1 from moci3 where p3 >0.5 group by type1) as a,(  select type1,count(*) as c2 from moci3     group by type1  ) as b where a.type1=b.type1";

                        sql = "select count(*),type1 from moci3 group by type1";

                        while(true) {

                            Date d1 = new Date();

                            Statement stmt = con.createStatement();
                            ResultSet rs = stmt.executeQuery(sql);
                            while (rs.next()){
                                rs.getString(1);


                            }
                            System.out.println(d1+"----"+new Date());
                            rs.close();
                            stmt.close();
                        }
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }


                }
            }.start();
        }



    }
}

 

10个并发,查询时间10秒左右

Thread[Thread-4,5,main]:Mon Nov 08 19:10:01 CST 2021----Mon Nov 08 19:10:02 CST 2021
Thread[Thread-6,5,main]:Mon Nov 08 19:10:01 CST 2021----Mon Nov 08 19:10:02 CST 2021
Thread[Thread-2,5,main]:Mon Nov 08 19:10:02 CST 2021----Mon Nov 08 19:10:02 CST 2021
Thread[Thread-0,5,main]:Mon Nov 08 19:10:02 CST 2021----Mon Nov 08 19:10:02 CST 2021
Thread[Thread-1,5,main]:Mon Nov 08 19:10:02 CST 2021----Mon Nov 08 19:10:02 CST 2021
Thread[Thread-7,5,main]:Mon Nov 08 19:10:01 CST 2021----Mon Nov 08 19:10:02 CST 2021
Thread[Thread-9,5,main]:Mon Nov 08 19:10:02 CST 2021----Mon Nov 08 19:10:02 CST 2021
Thread[Thread-8,5,main]:Mon Nov 08 19:10:02 CST 2021----Mon Nov 08 19:10:02 CST 2021
Thread[Thread-3,5,main]:Mon Nov 08 19:10:02 CST 2021----Mon Nov 08 19:10:02 CST 2021
Thread[Thread-5,5,main]:Mon Nov 08 19:10:02 CST 2021----Mon Nov 08 19:10:02 CST 2021
Thread[Thread-4,5,main]:Mon Nov 08 19:10:02 CST 2021----Mon Nov 08 19:10:03 CST 2021
Thread[Thread-0,5,main]:Mon Nov 08 19:10:02 CST 2021----Mon Nov 08 19:10:03 CST 2021

 

posted on 2021-11-08 19:10  李雷  阅读(1121)  评论(0编辑  收藏  举报

导航