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