【问题标题】:Is this possible to load data into memory using Spark when the Spring Boot Application starts ?这是否可以在 Spring Boot 应用程序启动时使用 Spark 将数据加载到内存中?
【发布时间】:2017-05-03 13:12:56
【问题描述】:

我是 Spark 和 Spring Boot 框架的新手。我曾尝试在 3 个节点的 spark 集群中处理 1 亿条数据库记录,每个节点有 16 Gigs 的 RAM 和 4 个核心,在我将完整的 1 亿条记录缓存在内存中之后,它的工作速度非常快,所以我的主要目标是当我的 spring boot 应用程序(我正在编写它以创建一些将在 spark 上下文中运行的 RESTful 服务)启动时加载并缓存内存中的记录。如何在应用程序启动时准确加载和缓存 1 亿条记录。

【问题讨论】:

    标签: java apache-spark spring-boot


    【解决方案1】:

    您可以监听应用程序的启动并启动一个线程来加载您的记录。

    public class CacheLoadListener implements ApplicationListener {
    
        @Override
        public void onApplicationEvent(ApplicationEvent event) {
            if (event instanceof ContextRefreshedEvent) {
                //Start a thread/job to load your data
            }
        }
    }
    

    在配置文件中

    @Bean
    public CacheLoadListener cacheLoadListener() {
        return new CacheLoadListener();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      • 2018-08-28
      • 1970-01-01
      • 2015-07-12
      • 2015-10-21
      • 2015-02-21
      相关资源
      最近更新 更多