Coherence装载数据的研究-PreloadRequest
最近给客户准备培训,看到Coherence可以通过三种方式批量加载数据,分别是:
- Custom application
- InvocableMap - PreloadRequest
- Invocation Service
Custom application的方式简单易懂,基本就是通过put和putAll方法实现,就不再纠结了。但问题是无论是put还是putAll
都是一个串行过程,如果装载大量数据的话,就需要有一种并行机制实现并行装载。
本文对第二种方式InvocableMap做一些研究,PreloadRequest主要是基于一个entry的集合通过Cache Loader进行装载,
其命令主要是:
包含如下特征:
- 装载前必须知道要装载的所有的key值。
- 本身装载的动作通过CacheLoader来实现。
- 装载是并行过程,每个存储节点负责把分布在自己Cache的内容按照key值,从数据库中装载
代码:
Person.java
package dataload; import java.io.Serializable; public class Person implements Serializable { public void setId(String Id) { public String getId() { public void setFirstname(String Firstname) { public String getFirstname() { public void setLastname(String Lastname) { public String getLastname() { public void setAddress(String Address) { public String getAddress() { public Person() { public Person(String sId,String sFirstname,String sLastname,String sAddress) { |
实现CacheLoader的DBCacheStore.java,比较核心的是看load方法
package dataload; import com.tangosol.net.CacheFactory; import com.tangosol.util.InvocableMap; import java.sql.DriverManager; import java.util.Collection; import javax.naming.Context; import java.sql.ResultSet; import java.util.Collections; import javax.naming.NamingException; /** } // ---- accessors ------------------------------------------------------- /** /** Hashtable<String,String> ht = new Hashtable<String,String>(); m_con = ds.getConnection(); return m_con; // ----- CacheStore Interface -------------------------------------------- /** try stmt.setString(1, String.valueOf(oKey)); if (rslt.next()) } System.out.println("=============="+e.getMessage()); //throw ensureRuntimeException(e, "Load failed: key=" + oKey); /** if (load(oKey) != null) /** stmt.setString(1, String.valueOf(oKey)); /** /** /** /** try return list.iterator(); // ----- data members --------------------------------------------------- /** /** protected NamedCache cache; |
CoherencePreLoad.java程序
package dataload; import java.sql.ResultSet; import com.tangosol.util.InvocableMap; import java.sql.Connection; import java.util.Collection; import javax.naming.Context; public class CoherencePreLoad { public static void main(String[] args) { NamedCache cache = CacheFactory.getCache("SampleCache"); String sql = "select id from persons order by id"; try{ Context ctx = null; Hashtable<String,String> ht = new Hashtable<String,String>(); con = ds.getConnection(); while (rs.next()) { // this loads 1000 items at a time into the cache }catch (Exception e) { |
然后需要在缓存的配置中进行设置
<?xml version="1.0"?> <read-write-backing-map-scheme> <internal-cache-scheme> <cachestore-scheme> <listener/> </caching-schemes> |
需要注意的是,必须在启动Cache-server的时候加入weblogic.jar以及dataload的包,因为在DBCacheStore中用到了weblogic JNDI去寻找数据源。
输出结果如下:
在jdeveloper端的Coherence节点
在coherence server端的存储节点
通过visualVM监控是否已经写入缓存
Coherence装载数据的研究-PreloadRequest的更多相关文章
- Coherence装载数据的研究 - Invocation Service
这里验证第三个方法,原理是将需要装载的数据分载在所有的存储节点上,不同的地方是利用了存储节点提供的InvocationService进行装载,而不是PreloadRequest, 原理如图 前提条件是 ...
- 使用 Hive装载数据的几种方式
装载数据 1.以LOAD的方式装载数据 LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE tablename [PARTITION( ...
- db2 load命令装载数据时定位错误出现的位置
使用如下命令装载数据(注意CPU_PARALLELISM 1): db2 load from filename.del of del replace into tab_name CPU_PARALL ...
- 总结一下用caffe跑图片数据的研究流程
近期在用caffe玩一些数据集,这些数据集是从淘宝爬下来的图片.主要是想研究一下对女性衣服的分类. 以下是一些详细的操作流程,这里总结一下. 1 爬取数据.写爬虫从淘宝爬取自己须要的数据. 2 数据预 ...
- 对Yii 2.0模型rules的理解(load()无法正确装载数据)
在实际开发中,遇到数据表新增字段而忘记了在对应模型中rules规则中添加新增的字段,而导致load()方法装载不到新增字段,导致新增字段无法写入数据库中. 解决办法:在新增字段后及时在对应模型ru ...
- [大数据学习研究]1.在Mac上利用VirtualBox搭建本地虚拟机环境
1. 大数据和Hadoop 研究学习大数据,自然要从Hadoop开始. Hadoop不是一个简单的软件,而是有一些列软件形成的生态,其核心思想来自Google当初发布的三篇论文,后来做了开源的实现, ...
- android的liveview装载数据
设置布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:andro ...
- (转载)IQ 16.0 SP02起支持从压缩文件直接装载数据到表中
参考文档: http://m.blog.chinaunix.net/uid-16765068-id-4405877.htmlhttp://www.cnblogs.com/lichmama/p/4103 ...
- [大数据学习研究]2.利用VirtualBox模拟Linux集群
1. 在主机Macbook上设置HOST 前文书已经把虚拟机的静态IP地址设置好,以后可以通过ip地址登录了.不过为了方便,还是设置一下,首先在Mac下修改hosts文件,这样在ssh时就不用输入ip ...
随机推荐
- bzoj 2753 最小生成树变形
我们根据高度建图,将无向边转化为有向边 首先对于第一问,直接一个bfs搞定,得到ans1 然后第二问,我们就相当于要求找到一颗最小生成树, 满足相对来说深度小的高度大,也就是要以高度为优先级 假设现在 ...
- 爆破phpmyadmin小脚本
#!usr/bin/env python #encoding: utf-8 #by i3ekr import requests headers = {'Content-Type':'applicati ...
- kvm源代码分析
vmx是x86硬件虚拟化层,从代码看,qemu用户态是一层,kernel中KVM通用代码是一层,类似kvm_x86_ops是一层,针对各个不同的硬件架构,而vcpu_vmx则是具体架构的虚拟化方案一层 ...
- Winform常用操作
>> c#操作cmd命令 using System.Diagnostics; private string RunCmd(string command) { //实例一个Process类, ...
- [ Linux 命令 ] grep
一.grep是什么? Linux grep命令是用于查找文件里符合条件行的shell命令. 二.为什么要使用grep? 在查找文件内容时候,通过使用grep指定条件,可以快速定位到文件里字符串所在的行 ...
- spring FieldRetrievingFactoryBean
Spring : 基于XML Schema的配置(一): http://www.tuicool.com/articles/mMjY3uI http://www.cnblogs.com/jifeng/a ...
- MATLAB规划问题——线性规划和非线性规划
1.线性规划 求线性规划问题的最优解有两种方法,一种方法是使用linprog命令,另一种是使用optimtool工具箱,下面分别介绍这两种方法. ①linprog命令 一般情况下,Linprog命令的 ...
- 转:Laravel 安装指南
Git 介绍 之所以要说 Git,就是因为 Composre 有时需要用到 Git,还是安装上比较好,Composer 暂且不表,先来了解一下 Git 吧(已经安装的童鞋跳过这里,直接看 Compos ...
- validate+jquery+ajax表单验证
1.案例 1.1 Html form表单内容 <form class="cForm" id="cForm" method="post" ...
- Problem B: 英雄无敌3(2)【模拟,日期转换】
Problem B: 英雄无敌3(2) Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 295 Solved: 52[Submit][Status][W ...