hive job sql 优化 之CPU占有太高

最近有个SQL运行时长超过两个小时,因此准备优化下html

首先查看hive sql 产生job的counter数据发现java

总的CPU time spent 太高估计100.4319973小时正则表达式

wKioL1VlFr6hWeoTAAF9ENBUpKY216.jpg

 

每一个mapCPU time spentsql

wKioL1VlFr7AJlcQAALkdoRGTVE652.jpg

 

排第一的耗了2.0540889小时apache


建议设置以下参数:ide

1mapreduce.input.fileinputformat.split.maxsize如今是256000000   往下调增长map数(此招立竿见影,我设为32000000产生了500+的map,最后任务由原先的2小时提速到47分钟就完成oop

2、优化UDF  getPageID  getSiteId getPageValue (这几个方法用了不少正则表达式的文本匹配)优化

     2.1 正则表达式处理优化能够参考lua

    http://www.fasterj.com/articles/regex1.shtmlurl

    http://www.fasterj.com/articles/regex2.shtml


     2.2  UDF优化见

1 Also you should use class level privatete members to save on object
 incantation and garbage collection.

2 You also get benefits by matching the args with what you would normally
 expect from upstream. Hive converts text to string when needed, but if the
 data normally coming into the method is text you could try and match the
 argument and see if it is any faster.
 Exapmle:
 优化前:
 >>>> import org.apache.hadoop.hive.ql.exec.UDF;
>>>> import java.net.URLDecoder;
>>>>
>>>> public final class urldecode extends UDF {
>>>>
>>>>    public String evaluate(final String s) {
>>>>        if (s == null) { return null; }
>>>>        return getString(s);
>>>>    }
>>>>
>>>>    public static String getString(String s) {
>>>>        String a;
>>>>        try {
>>>>            a = URLDecoder.decode(s);
>>>>        } catch ( Exception e) {
>>>>            a = "";
>>>>        }
>>>>        return a;
>>>>    }
>>>>
>>>>    public static void main(String args[]) {
>>>>        String t = "%E5%A4%AA%E5%8E%9F-%E4%B8%89%E4%BA%9A";
>>>>        System.out.println( getString(t) );
>>>>    }
>>>> }

优化后:

import java.net.URLDecoder;

public final class urldecode extends UDF {

    private Text t = new Text();

    public Text evaluate(Text s) {
        if (s == null) { return null; }
        try {
            t.set( URLDecoder.decode( s.toString(), "UTF-8" ));
            return t;
        } catch ( Exception e) {
            return null;
        }
    }

    //public static void main(String args[]) {
        //String t = "%E5%A4%AA%E5%8E%9F-%E4%B8%89%E4%BA%9A";
        //System.out.println( getString(t) );
    //}
}
3  继承实现GenericUDF

3、若是是Hive 0.14 +  能够开启hive.cache.expr.evaluation  UDF Cache功能

相关文章
相关标签/搜索