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();
    }
    }

  • 相关阅读:
    一套C#语言的日志控制系统
    unity自义定摇杆
    2014 西安邀请赛小结
    Poj 1112 Team Them Up!
    Poj 1112 Rebuilding Roads(树形DP+背包)
    USACO Cow Pedigrees
    Poj 2284 That Nice Euler Circuit
    LA 3942 Remember the Word
    HDU 3065 病毒侵袭持续中
    HDU 2896 病毒侵袭
  • 原文地址:https://www.cnblogs.com/huiandong/p/9194604.html
Copyright © 2011-2022 走看看