最近有個SQL運行時長超過兩個小時,所以準備優(yōu)化下
成都創(chuàng)新互聯(lián)公司專注于成都做網(wǎng)站、成都網(wǎng)站設計、網(wǎng)頁設計、網(wǎng)站制作、網(wǎng)站開發(fā)。公司秉持“客戶至上,用心服務”的宗旨,從客戶的利益和觀點出發(fā),讓客戶在網(wǎng)絡營銷中找到自己的駐足之地。尊重和關懷每一位客戶,用嚴謹?shù)膽B(tài)度對待客戶,用專業(yè)的服務創(chuàng)造價值,成為客戶值得信賴的朋友,為客戶解除后顧之憂。
首先查看hive sql 產(chǎn)生job的counter數(shù)據(jù)發(fā)現(xiàn)
總的CPU time spent過高估計100.4319973小時
每個map的CPU time spent
排第一的耗了2.0540889小時
建議設置如下參數(shù):
1、mapreduce.input.fileinputformat.split.maxsize現(xiàn)在是256000000 往下調(diào)增加map數(shù)(此招立竿見影,我設為32000000產(chǎn)生了500+的map,最后任務由原先的2小時提速到47分鐘就完成)
2、優(yōu)化UDF getPageID getSiteId getPageValue (這幾個方法用了很多正則表達式的文本匹配)
2.1 正則表達式處理優(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功能