apache ignite系列(二):配置
ignite有两种配置方式,一种是基于XML文件的配置,一种是基于JAVA代码的配置:
这里将ignite常用的配置集中罗列出来了,一般建议使用xml配置。
1,基于XML的配置
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="igniteCfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<!-- Consistent globally unique node identifier which survives node restarts. -->
<!-- 全局一致性id -->
<!--<property name="consistentId" value="cord"/>-->
<!--Set to true to enable distributed class loading for examples, default is false. -->
<!-- 分布式计算class传播 -->
<property name="peerClassLoadingEnabled" value="true"/>
<!-- Set deployment mode. -->
<!-- 部署模式,控制类加载. -->
<property name="deploymentMode" value="CONTINUOUS"/>
<!-- Disable missed resources caching. -->
<!-- 禁用丢失资源缓存 -->
<property name="peerClassLoadingMissedResourcesCacheSize" value="0"/>
<!-- 设为false表示服务端模式 -->
<property name="clientMode" value="false"/>
<!-- Network timeout -->
<!-- 连接超时时间 -->
<property name="networkTimeout" value="10000" />
<!--Exclude force peer class loading of a class, even if exists locally.-->
<!-- 配置需要传播的class的路径 -->
<property name="peerClassLoadingLocalClassPathExclude">
<list>
<value>org.cord.*</value>
</list>
</property>
<!-- 配置需要监听的事件类型-->
<property name="includeEventTypes">
<list>
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT"/>
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ"/>
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED"/>
</list>
</property>
<!-- Configure internal thread pool. -->
<!-- 公共线程池大小-->
<property name="publicThreadPoolSize" value="64"/>
<!-- Configure system thread pool. -->
<!-- 系统线程池大小-->
<property name="systemThreadPoolSize" value="32"/>
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<!-- 缓存名-->
<property name="name" value="IGNITE_CACHE_KEY_PCOMM_RATE"/>
<!-- 原子模式类型,ATOMIC:原子型,保证性能; TRANSACTIONAL:事务型,分布式锁-->
<property name="atomicityMode" value="ATOMIC"/>
<!--PARTITIONED:分区; REPLICATED:复制;LOCAL:本地 -->
<property name="cacheMode" value="REPLICATED"/>
<!-- 备份数量-->
<property name="backups" value="1"/>
<!-- 禁用jcache标准中缓存读取获取的是副本的机制 -->
<property name="copyOnRead" value="false"/>
<!-- 内存区名-->
<property name="dataRegionName" value="Default_Region"/>
<!-- 是否以二进制形式存储-->
<!--<property name="storeKeepBinary" value="true"/>-->
<!-- 索引类型-->
<property name="indexedTypes">
<list>
<value>java.lang.Long</value>
<value>com.palic.demo.data.domain.CommRate</value>
</list>
</property>
</bean>
</list>
</property>
<!-- Redefining maximum memory size for the cluster node usage. -->
<property name="dataStorageConfiguration">
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
<!-- Redefining the default region's settings -->
<!-- 默认存储区间配置-->
<property name="defaultDataRegionConfiguration">
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<!-- 存储区名-->
<property name="name" value="Default_Region"/>
<!-- 存储区大小-->
<!-- Setting the size of the default region to 1GB. -->
<!--<property name="maxSize" value="#{1L * 1024 * 1024 * 1024}"/>-->
<property name="maxSize" value="#{512 * 1024 * 1024}"/>
<!-- 是否开启持久化-->
<!-- Enabling Apache Ignite Persistent Store. -->
<!--<property name="persistenceEnabled" value="true"/>-->
</bean>
</property>
<property name="dataRegionConfigurations">
<list>
<!-- 自定义内存区-->
<!--
Defining a data region that will consume up to 500 MB of RAM and
will have eviction and persistence enabled.
-->
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<!-- Custom region name. -->
<property name="name" value="500MB_Region"/>
<!-- 100 MB initial size. -->
<property name="initialSize" value="#{100L * 1024 * 1024}"/>
<!-- 500 MB maximum size. -->
<property name="maxSize" value="#{500L * 1024 * 1024}"/>
<!-- Enabling persistence for the region. -->
<!--<property name="persistenceEnabled" value="true"/>-->
</bean>
</list>
</property>
<!-- 预写日志模式-->
<!-- Sets property that defines behavior of wal fsync. -->
<!--<property name="walMode">-->
<!--<util:constant static-field="org.apache.ignite.configuration.WALMode.DEFAULT"/>-->
<!--</property>-->
<property name="walMode" value="DEFAULT"/>
<!-- 检查点频率-->
<!--Checkpointing frequency which is a minimal interval when the dirty pages will be written to the Persistent Store.-->
<property name="checkpointFrequency" value="180000"/>
<!--<property name="checkpointFrequency" value="10000"/>-->
<!-- 检查点线程数-->
<!-- Number of threads for checkpointing.-->
<property name="checkpointThreads" value="4"/>
<!-- 在检查点同步完成后预写日志历史保留数量 -->
<!-- Number of checkpoints to be kept in WAL after checkpoint is finished.-->
<property name="walHistorySize" value="20"/>
<!--<property name="walHistorySize" value="2"/>-->
<!-- 持久化文件路径 -->
<!--<!– Path where data and indexes will be persisted. –>-->
<!--<property name="storagePath" value="D:\\Test\\db" />-->
<!--<!– Path to the directory where WAL (Write Ahead Log) is stored. –>-->
<!--<property name="walPath" value="D:\\Test\\db\\wal" />-->
<!--<!– Path to the directory where WAL (Write Ahead Log) archive is stored. –>-->
<!--<property name="walArchivePath" value="D:\\Test\\db\\wal\\archive" />-->
</bean>
</property>
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="localPort" value="48500"/>
<property name="localPortRange" value="20"/>
<property name="joinTimeout" value="0"/>
<property name="networkTimeout" value="5000" />
<property name="ipFinder">
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
<property name="addresses">
<!-- 集群ip列表-->
<list>
<value>127.0.0.1:48500..48520</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
<property name="communicationSpi">
<bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi">
<property name="localPort" value="48100"/>
</bean>
</property>
</bean>
</beans>
基于此XML配置启动ignite节点的方式如下:
@Configuration
public class IgniteConfig {
@Autowired
private IgniteConfiguration igniteCfg;
@Bean
@ConditionalOnMissingBean
public Ignite initIgnite() {
//推荐借助spring bean的方式注入ignite配置信息,只需要将配置xml文件import即可
//启动类加上注解@ImportResource(locations={"classpath:default-config.xml"})
Ignite ignite = Ignition.start(igniteCfg);
//Ignite ignite = Ignition.start(classpath:default-config.xml)
}
}
2,基于JAVA代码的配置
......
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setClientMode(false);
//配置集群发现
cfg.setDiscoverySpi(new TcpDiscoverySpi().setLocalPort(48500).setLocalPortRange(20)
.setIpFinder(new TcpDiscoveryVmIpFinder().setAddresses(Arrays.asList("127.0.0.1:48500..48520"))));
//基本配置
cfg.setCommunicationSpi(new TcpCommunicationSpi().setLocalPort(48100));
cfg.setDeploymentMode(CONTINUOUS);
cfg.setPeerClassLoadingEnabled(true);
cfg.setPeerClassLoadingLocalClassPathExclude("com.org.ignite.*");
cfg.setIncludeEventTypes(EventType.EVT_TASK_STARTED, EventType.EVT_TASK_FINISHED, EventType.EVT_TASK_FAILED);
cfg.setPublicThreadPoolSize(64);
cfg.setSystemThreadPoolSize(32);
//添加cache配置
List<CacheConfiguration> cacheConf = new ArrayList<>();
CacheConfiguration<String, Integer> conf = new CacheConfiguration<String, Integer>("test")
.setCacheMode(CacheMode.REPLICATED)
.setIndexedTypes(String.class, Integer.class)
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setCopyOnRead(false)
.setBackups(1);
cacheConf.add(conf);
cfg.setCacheConfiguration(cacheConf.toArray(new CacheConfiguration[]{}));
//基于java代码配置启动
Ignition.start(cfg);
......
一般建议基于XML配置,spring bean注入,如果确实需要JAVA配置,可以结合XML配置灵活处理。
在ignite集群中,配置信息是可以动态传播的,而如果是修改配置文件,则需要重启节点才可生效,并且如果有些关键配置不一致,也会导致启动节点报错,无法加入集群。所以最好的做法是,在普通节点中只配置节点相关配置,以及集群发现配置,至于变动性最大的缓存cache配置,可以由应用节点配置,这样便于的集中管控缓存配置。除此之外,使用xml配置,可以保证普通节点与应用节点的配置的一致性,而不需要单独再维护一套代码配置。
apache ignite系列(二):配置的更多相关文章
- apache ignite系列(九):ignite调优
1,配置文件调优 1.1 设置页面大小(pagesize) 先查看系统pagesiz,使用PAGE_SIZE或者PAGESIZE # getconf PAGE_SIZE 4096 # getconf ...
- apache ignite系列(九):使用ddl和dml脚本初始化ignite并使用mybatis查询缓存
博客又断了一段时间,本篇将记录一下基于ignite对jdbc支持的特性在实际使用过程中的使用. 使用ddl和dml脚本初始化ignite 由于spring-boot中支持通过spring.dataso ...
- apache ignite系列(八):问题汇总
1,java.lang.ClassNotFoundException Unknown pair 1.Please try to turn on isStoreKeepBinary in cache s ...
- apache ignite系列(六): 服务网格
简介 服务网格本质上还是远程方法调用(RPC),而在ignite中注册的服务本质体现还是以cache的形式存在,集群中的节点可以相互调用部署在其它节点上的服务,而且ignite集群会负责部署服务的 ...
- apache ignite系列(四):持久化
ignite持久化与固化内存 1.持久化的机制 ignite持久化的关键点如下: ignite持久化可防止内存溢出导致数据丢失的情况: 持久化可以定制化配置,按需持久化; 持久化能解决在大量缓存数据情 ...
- apache ignite系列(三):数据处理(数据加载,数据并置,数据查询)
使用ignite的一个常见思路就是将现有的关系型数据库中的数据导入到ignite中,然后直接使用ignite中的数据,相当于将ignite作为一个缓存服务,当然ignite的功能远不止于此,下面以 ...
- apache ignite系列(一): 简介
apache-ignite简介(一) 1,简介 ignite是分布式内存网格的一种实现,其基于java平台,具有可持久化,分布式事务,分布式计算等特点,此外还支持丰富的键值存储以及SQL语法(基于 ...
- apache ignite系列(五):分布式计算
ignite分布式计算 在ignite中,有传统的MapReduce模型的分布式计算,也有基于分布式存储的并置计算,当数据分散到不同的节点上时,根据提供的并置键,计算会传播到数据所在的节点进行计算,再 ...
- 深入浅出Mybatis系列二-配置简介(mybatis源码篇)
注:本文转载自南轲梦 注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 上篇文章<深入浅出Mybatis系列(一)---Mybatis入门>, ...
随机推荐
- Zookeeper_阅读源码第一步_在 IDE 里启动 zkServer(集群版)
上篇文章Zookeeper_阅读源码第一步_在 IDE 里启动 zkServer(单机版)讲了在 idea 里以单机的方式启动zookeeper,这篇介绍一下以集群的方式启动. 集群方式启动,才会真正 ...
- Codeforces 343D Water Tree
题意简述 维护一棵树,支持以下操作: 0 v:将以v为跟的子树赋值为1 1 v:将v到根节点的路径赋值为0 2 v:询问v的值 题解思路 树剖+珂朵莉树 代码 #include <set> ...
- python+爬虫+微信机器人 打造属于你的网购价格监督利器
写在最前 程序是为人类服务的,最近正好身边小伙伴们在做球衣生意,当然是去nikenba专区购买了,可是有些热门球衣发布几分钟就被抢完,有些折扣球衣也是很快就被抢售一空,那么我们只能靠自己的眼睛一直盯着 ...
- 建立apk定时自动打包系统第三篇——代码自动更新、APP自动打包系统
我们的思路是每天下班后团队各成员在指定的时间(例如下午18:30)之前把各自的代码上传到SVN,然后服务器在指定的时间(例如下午18:30)更新代码.执行ant 打包命令.最后将apk包存放在指定目录 ...
- 【原创】display:flex布局大全
全都是自己写的 希望大家可以点个赞 谢谢! Html代码(没时间精简 请多包涵) <!DOCTYPE html> <html lang="en"> < ...
- SoapUI使用教程---简介、下载、破解
最近项目中要使用到SoapUI这款测试工具,之前有接触过,但好久没用了,借此机会记录并和大家分享一下. 一.soapui简介 soapui是一款开源测试工具,通过soap/http来检查.调用.实现W ...
- 打包一沓开源的 C/C++ 包管理工具送给你!
本文作者:HelloGitHub-ChungZH 博客地址:https://chungzh.cn/ 包管理器可以帮助你更方便地安装依赖关系,并决定所安装的版本,提高你的开发幸福感.许多语言都有自己的包 ...
- HandlerMethodArgumentResolver(二):Map参数类型和固定参数类型【享学Spring MVC】
每篇一句 黄金的导电性最好,为什么电脑主板还是要用铜? 飞机最快,为什么还有人做火车? 清华大学最好,为什么还有人去普通学校? 因为资源都是有限的,我们现实生活中必须兼顾成本与产出的平衡 前言 上文 ...
- Leetcode之深度优先搜索&回溯专题-980. 不同路径 III(Unique Paths III)
Leetcode之深度优先搜索&回溯专题-980. 不同路径 III(Unique Paths III) 深度优先搜索的解题详细介绍,点击 在二维网格 grid 上,有 4 种类型的方格: 1 ...
- 导航页的开发--手机web app开发笔记
好了,的所有的基础知识已经准备完毕了,现在开始制作引导页.这个引导页需要一个HTML文件,JS文件,一个CSS文件.在HBuilderX中根目录下添加“Guid.html”,在JS文件夹添加“myth ...