Hive性能測試

Hive性能測試

有時候我們需要對Hive cluster做性能測試,如下的代碼就是用多線程的方式對hive查詢,300個線程作查詢,從而測試hive的返回速度。

package jdbc;
 
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
//import java.sql.SQLException;
import java.sql.Statement;
 
// Java code for thread creation by extending
// the Thread class
public class App implements Runnable
{
     public void run() {
 
       for(int i = 0; i < 10; i++) {
          try {
              Class.forName("org.apache.hive.jdbc.HiveDriver");
              Connection conn = DriverManager.getConnection("jdbc:hive2://headnodeFQDN:10001/;principal=hive/_HOST@domainname;transportMode=http", "[email protected]", "password");
              Statement stat = conn.createStatement();
              ResultSet rs = stat.executeQuery("select * from `default`.sampletable where devicemake = 'Device' limit 10");
 
 
                  while (rs.next()) {
                  System.out.println(Thread.currentThread().getId()+ ", clientId:" + rs.getInt(1));
              }
              rs.close();
              conn.close();
          } catch (Exception ex) {
              System.out.println("exception:" + ex.getMessage());
          }
}
}
 
    public static void main( String[] args ) throws Exception {
            for(int i = 0; i < 300; i++){
                App app = new App();
                (new Thread(app)).start();
                }
 
     }
}
發佈了13 篇原創文章 · 獲贊 0 · 訪問量 966
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章