zoukankan      html  css  js  c++  java
  • CacheTest

    package com.bjsxt.spark.others;

    import org.apache.spark.SparkConf;
    import org.apache.spark.api.java.JavaRDD;
    import org.apache.spark.api.java.JavaSparkContext;
    import org.apache.spark.storage.StorageLevel;
    public class CacheTest{
    public static void main(String[] args) {
    SparkConf conf = new SparkConf();
    conf/*.setMaster("local")*/.setAppName("CacheTest");
    JavaSparkContext jsc = new JavaSparkContext(conf);
    JavaRDD<String> lines = jsc.textFile("hdfs://node1:9000/test/NASA_access_log_Aug95");
    // lines = lines.cache();
    // lines = lines.persist(StorageLevel.MEMORY_ONLY_2());
    lines = lines.persist(new StorageLevel(false, true, false, true, 3));
    long startTime = System.currentTimeMillis();
    long count = lines.count();
    long endTime = System.currentTimeMillis();
    System.out.println("共"+count+ "条数据,"+"初始化时间+cache时间+计算时间="+ (endTime-startTime));
    /*
    long countStartTime = System.currentTimeMillis();
    long countrResult = lines.count();
    long countEndTime = System.currentTimeMillis();
    System.out.println("共"+countrResult+ "条数据,"+"计算时间="+ (countEndTime-countStartTime));
    lines.unpersist();
    long countStartTime2 = System.currentTimeMillis();
    long countrResult2 = lines.count();
    long countEndTime2 = System.currentTimeMillis();
    System.out.println("共"+countrResult2+ "条数据,"+"计算时间="+ (countEndTime2-countStartTime2));*/


    // lines.unpersist();
    while(true){

    }

    // jsc.stop();
    }
    }

  • 相关阅读:
    线程运行boost库在工作(22)任务之二
    vi 帮助文档 man vi
    跳槽关系三国演义告诉我们的60条真理
    后台端口虚拟主机wdcp的相关问题以及解决方法
    格式化字符串android 格式化时间
    对象查询HQL多表联合查询的问题
    myeclipse8.6中svn插件的安装
    乱码解决方法
    Restfull风格是什么意思?
    poj3013
  • 原文地址:https://www.cnblogs.com/huiandong/p/9194604.html
Copyright © 2011-2022 走看看