zoukankan      html  css  js  c++  java
  • spark持久化

    package com.wll;
    import org.apache.spark.SparkConf;
    import org.apache.spark.api.java.JavaRDD;
    import org.apache.spark.api.java.JavaSparkContext;
    public class Persist {
        static SparkConf conf=new SparkConf().setMaster("local").setAppName("persist");
        static JavaSparkContext sc=new JavaSparkContext(conf);
        public static void main(String[] args){
            noCache();
            //cache();
        }
        public static void noCache(){
    
            JavaRDD<String> list=sc.textFile("C:\Users\wanglonglong\Desktop\hive-default.xml");
            long beginTime=System.currentTimeMillis();
            long count=list.count();
            System.out.println("无持久化第一次"+(System.currentTimeMillis()-beginTime));
    
            beginTime=System.currentTimeMillis();
            count=list.count();
            System.out.println("无持久化第二次"+(System.currentTimeMillis()-beginTime));
        }
        public static void cache(){
            JavaRDD<String> list=sc.textFile("C:\Users\wanglonglong\Desktop\hive-default.xml").cache();
            long beginTime=System.currentTimeMillis();
            long count=list.count();
            System.out.println("持久化第一次"+(System.currentTimeMillis()-beginTime));
    
            beginTime=System.currentTimeMillis();
            count=list.count();
            System.out.println("持久化第二次"+(System.currentTimeMillis()-beginTime));
        }
    }
  • 相关阅读:
    day35作业
    进程的初识
    day34作业
    python中的文件
    python字典概述
    python中的深拷贝与浅拷贝
    python的元组和列表使用之一
    Python基本数据类型
    python的编码
    windows中安装python
  • 原文地址:https://www.cnblogs.com/wakerwang/p/9568440.html
Copyright © 2011-2022 走看看