hivejobsql優(yōu)化之CPU占有過高

最近有個SQL運行時長超過兩個小時,所以準(zhǔn)備優(yōu)化下

成都創(chuàng)新互聯(lián)公司專注于成都做網(wǎng)站、成都網(wǎng)站設(shè)計、網(wǎng)頁設(shè)計、網(wǎng)站制作、網(wǎng)站開發(fā)。公司秉持“客戶至上,用心服務(wù)”的宗旨,從客戶的利益和觀點出發(fā),讓客戶在網(wǎng)絡(luò)營銷中找到自己的駐足之地。尊重和關(guān)懷每一位客戶,用嚴(yán)謹(jǐn)?shù)膽B(tài)度對待客戶,用專業(yè)的服務(wù)創(chuàng)造價值,成為客戶值得信賴的朋友,為客戶解除后顧之憂。

首先查看hive sql 產(chǎn)生job的counter數(shù)據(jù)發(fā)現(xiàn)

總的CPU time spent過高估計100.4319973小時

hive job sql  優(yōu)化 之CPU占有過高

 

每個map的CPU time spent

hive job sql  優(yōu)化 之CPU占有過高

 

排第一的耗了2.0540889小時

建議設(shè)置如下參數(shù):

1、mapreduce.input.fileinputformat.split.maxsize現(xiàn)在是256000000   往下調(diào)增加map數(shù)(此招立竿見影,我設(shè)為32000000產(chǎn)生了500+的map,最后任務(wù)由原先的2小時提速到47分鐘就完成)

2、優(yōu)化UDF  getPageID  getSiteId getPageValue (這幾個方法用了很多正則表達(dá)式的文本匹配)

     2.1 正則表達(dá)式處理優(yōu)化可以參考

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

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

     2.2  UDF優(yōu)化見

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:
 優(yōu)化前:
 >>>> 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) );
>>>>    }
>>>> }

優(yōu)化后:

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  繼承實現(xiàn)GenericUDF

3、如果是Hive 0.14 + 可以開啟hive.cache.expr.evaluation  UDF Cache功能

當(dāng)前文章:hivejobsql優(yōu)化之CPU占有過高
標(biāo)題網(wǎng)址:http://bm7419.com/article10/gigpgo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、云服務(wù)器、虛擬主機(jī)、App設(shè)計網(wǎng)站設(shè)計公司、響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站