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();
}
}
}