从In Memory Data Grid,Apache Ignite快速入门

IMDG或内存数据网格不是内存中关系数据库,NOSQL数据库或关系数据库。 它是另一种软件数据存储库。 数据模型分布在单个位置或多个位置的许多服务器上。 这种分布称为数据结构。 这种分布式模型被称为“无共享”架构。 IMDG具有以下特征:

  1. 所有服务器可以在每个站点中处于活动状态。
  2. 所有数据都存储在服务器的RAM中。
  3. 可以不中断地添加或删除服务器,以增加可用的RAM量。
  4. 数据模型是非关系的,是基于对象的。
  5. 用平台独立语言编写的分布式应用程序。
  6. 数据结构具有弹性,可以无中断地自动检测和恢复单个或多个服务器。

大多数情况下,我们将IMDG用于应用程序服务器的Web会话管理,并用作分布式缓存或L2缓存。 Hazelcast社区的添加是我们一直以来最喜欢的IMDG工具,但是从hazelcast社区版的最新情况来看,它的性能让我们感到非常不满意。 作为HazelCast的快速替代方案,我们决定尝试使用
Apache点燃 。 这篇文章专门针对apache点燃,可用于快速启动指南。 对于安装,我将使用具有以下配置的2个Redhat操作系统虚拟机:

  • CPU:2
  • 内存:4
  • 硬盘:25 GB
  • 操作系统:Redhat Santiago

从Apache ignite6的许多功能中,我们将仅研究以下功能:

  1. 准备操作系统
  2. 使用Spring使用DataGrid
  3. MyBatis缓存配置
  4. Spring缓存

安装apache点燃

前提条件:

  1. Java 1.7及更高版本
  2. 打开端口:47500..47509、8080(用于Rest接口),47400、47100:47101、48100:48101、31100:31101在操作系统中安装JDK之后,我们必须打开上述端口。 通过执行以下命令,我们可以操纵iptables。
    vi /etc/sysconfig/iptables
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 47500:47509 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 47400 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 47100 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 47101 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 48100 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 48101 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 31100 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 31101 -j ACCEPT/etc/init.d/iptables restart

在几台机器上安装Apache ignite

  1. 让我们从以下链接下载ignite 1.5.0final版本。
  2. 将档案解压缩到os中的任何位置,例如/ opt / apache-ignite
  3. 将环境路径IGNITE_HOME添加到apache ignite的主目录中。
  4. 将文件夹$ IGNITE_HOME / libs / optional / ignite-rest-http复制到/home/user/apache-ignite-fabric-1.5.0/libs,它将通过REST接口启用apign点火。
  5. 运行命令ignite.sh examples / config / example-cache.xml以启动apache ignite。

    如果一切正常,您应该在控制台中看到以下日志:

    [12:32:01] Ignite node started OK (id=ceb614ca)
    [12:32:01] Topology snapshot [ver=4, servers=2, clients=0, CPUs=3, heap=2.0GB]

    并且通过网址http:// host:port / ignite?cmd = version也可以通过http获得ignite

使用Spring使用DataGrid

首先,我们必须构建Maven项目以编写一堆代码来检查apache Ignite的功能。

    • 将以下依赖项添加到pom.xml
      <dependency><groupId>org.apache.ignite</groupId><artifactId>ignite-core</artifactId><version>${ignite.version}</version></dependency><dependency><groupId>org.apache.ignite</groupId><artifactId>ignite-spring</artifactId><version>${ignite.version}</version></dependency><dependency><groupId>org.apache.ignite</groupId><artifactId>ignite-indexing</artifactId><version>${ignite.version}</version></dependency><!-- myBatis --><dependency><groupId>org.mybatis.caches</groupId><artifactId>mybatis-ignite</artifactId><version>1.0.0-beta1</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>1.2.4</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.3.1</version></dependency><!-- Oracle 12--><dependency><groupId>com.oracle</groupId><artifactId>ojdbc6</artifactId><version>11.2.0.3</version></dependency>

      请注意,Oracle JDBC客户端jar应该位于本地Maven存储库中。 就我而言,我使用Oracle 11.2.02客户端。

    • 使用以下上下文在资源目录中添加spring-context.xml文件:
      <beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:cache="http://www.springframework.org/schema/cache"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/cachehttp://www.springframework.org/schema/cache/spring-cache-3.1.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd "><!-- Enable annotation-driven caching. --><cache:annotation-driven/><context:property-placeholder location="classpath:jdbc.properties"/><!-- beans --><bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"><property name="gridName" value="TestGrid"/><!-- Enable client mode. --><property name="clientMode" value="true"/><property name="cacheConfiguration"><list><!-- Partitioned cache example configuration (Atomic mode). --><bean class="org.apache.ignite.configuration.CacheConfiguration"><!--<property name="atomicityMode" value="ATOMIC"/>--><!-- Set cache mode. --><property name="cacheMode" value="PARTITIONED"/><property name="backups" value="1"/><property name="statisticsEnabled" value="true" /></bean></list></property><!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. --><property name="discoverySpi"><bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"><property name="ipFinder"><!-- Uncomment static IP finder to enable static-based discovery of initial nodes. --><!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">--><bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder"><property name="addresses"><list><!-- In distributed environment, replace with actual host IP address. --><value>Add your node ip address</value><value>add your node ip address</value></list></property></bean></property></bean></property></bean><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="mapperLocations" value="classpath*:com/blu/ignite/dao/*Mapper.xml"/></bean><bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close"><property name="URL" value="${jdbc.url}" /><property name="user" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/><property name="connectionCachingEnabled" value="true"/></bean>
      </beans>

      让我们检查一些配置属性:

      • 属性名称=“ clientMode”值=“ true” –此属性将强制当前应用程序作为客户端运行。
      • 属性名称=“ cacheMode”值=“已分配” –缓存模式将被分区,缓存模式也可被复制。
      • 属性名=“备份”值=“ 1” –总是在另一个节点中有一个冗余的缓存元素。
      • 属性名称=“ statisticsEnabled”值=“ true” –此属性将激活缓存统计信息。
    • 现在让我们写一些:
      public class SpringIgniteRun {public static void main(String[] args) throws Exception{System.out.println("Run Spring example!!");ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-core.xml");IgniteConfiguration igniteConfiguration = (IgniteConfiguration) ctx.getBean("ignite.cfg");Ignite ignite = Ignition.start(igniteConfiguration);// get or create cacheIgniteCache cache = ignite.getOrCreateCache("myCacheName");for(int i = 1; i < 1000; i++){cache.put(i, Integer.toString(i));}for(int i =1; i<1000;i++){System.out.println("Cache get:"+ cache.get(i));}Thread.sleep(20000); // sleep for 20 seconds// statisticsSystem.out.println("Cache Hits:"+ cache.metrics(ignite.cluster()).getCacheHits());ignite.close();}
      }

      上面的代码是自我解释的,我们只创建一个名为“ myCacheName”的缓存,并添加1000 String整数值。 将值插入缓存后,我们还从缓存中读取元素并检查统计信息。 通过ignitevisorcmd,您还可以监视数据网格,随后您可以找到网格统计信息的屏幕截图

      屏幕截图2016-02-18 at 16.24.20

    • MyBatis缓存配置

      现在,让我们添加MyBatis ORM l2缓存并检查其工作方式。

    <bean id="servicesBean" class="com.blu.ignite.WebServices"><property name="dao" ref="userServicesBean"/></bean><bean id="userServicesBean" class="com.blu.ignite.dao.UserServices"><property name="userMapper" ref="userMapper"/></bean><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="mapperLocations" value="classpath*:com/blu/ignite/dao/*Mapper.xml"/></bean><bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close"><property name="URL" value="${jdbc.url}" /><property name="user" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/><property name="connectionCachingEnabled" value="true"/></bean><bean id="userMapper" autowire="byName" class="org.mybatis.spring.mapper.MapperFactoryBean"><property name="mapperInterface" value="com.blu.ignite.mapper.UserMapper" /><property name="sqlSessionFactory" ref="sqlSessionFactory" /></bean><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.blu.ignite.mapper" /></bean>

    我们添加了SQLsessionFactory,MyBatis映射器和Service Bean。 现在让我们添加* .Mapper.xml

    <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.blu.ignite.mapper.UserMapper"><cache type="org.mybatis.caches.ignite.IgniteCacheAdapter" /><select id="getUser" parameterType="String" resultType="com.blu.ignite.dto.User" useCache="true">SELECT * FROM users WHERE id = #{id}</select><select id="getUniqueJob" parameterType="String" resultType="String" useCache="false">select unique job from emp order by job desc</select></mapper>

    emp和dept表的完整sql(DDL / DML)脚本位于com / blu / ignite / scripts目录中。我创建了一个简单的Web服务,以获取用户和员工的独特工作。 这是Web服务的代码,如下所示:

    @WebService(name = "BusinessRulesServices",serviceName="BusinessRulesServices",targetNamespace = "http://com.blu.rules/services")
    public class WebServices {private UserServices userServices;@WebMethod(operationName = "getUserName")public String getUserName(String userId){User user = userServices.getUser(userId);return user.getuName();}@WebMethod(operationName = "getUniqueJobs")public List getUniqueJobs(){return userServices.getUniqueJobs();}@WebMethod(exclude = true)public void setDao(UserServices userServices){this.userServices = userServices;}}

    调用Web方法getUserName将查询数据库并将查询结果缓存在ignite缓存中。

    Spring缓存

    使用spring缓存,您可以实现任何spring bean方法的返回值的缓存。 Apache ignite将通过您将通过注释@Cacheable(“ returnHello”)提供的缓存名称来创建缓存,例如,如果我具有如下方法:

    @Cacheable("returnHello")public String sayhello(String str){System.out.println("Client says:"+ str);return "hello"+str;}

    第一次调用该方法时,将在ignite中创建一个带有参数名称的复制缓存,下次调用上述方法时,将从缓存中返回该值。

    屏幕截图2016-02-18 at 18.48.17

    • 现在就足够了。 很快我将以apache ignite的一些新功能返回。 该项目的完整源代码可在github中找到。

    翻译自: https://www.javacodegeeks.com/2016/02/quick-start-memory-data-grid-apache-ignite.html

    本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/354054.shtml

    如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

    相关文章

    python字典合并几种方式对比,Python合并两个字典的常用方法与效率比较

    本文实例讲述了Python合并两个字典的常用方法与效率比较。分享给大家供大家参考。具体分析如下&#xff1a;下面的代码举例了5种合并两个字典的方法&#xff0c;并且做了个简单的性能测试#!/usr/bin/pythonimport timedef f1(d1,d2):return dict(d1,**d2)def f2(d1,d2):return …

    91.91p10.space v.php,luogu P1091 合唱队形

    任务计划推了很久才做www从两头开始的单调上升队列没啥可说的#include#includeusing namespace std;#define maxn 110int a[maxn];int f[2][maxn];int ans;int main() {int n;scanf("%d",&n);for(int i 1; i < n; i)scanf("%d",&a[i]);a[0] a…

    oracle查询大小写敏感参数,让Oracle 大小写敏感 表名 字段名 对像名

    一、解决方案1、在表名、字段名、对象名上加上双引号&#xff0c;即可实现让oracle大小写区分。2、但是这又引起了另一个问题&#xff1a;在数据库操作中&#xff0c;sql语句中相应的表名、字段名、对象名上一定要加双引号。解决办法是&#xff1a;使用"\"转义。如&a…

    BZOJ 2097 [Usaco2010 Dec]Exercise 奶牛健美操

    【题意】 给出一棵树。现在可以在树中删去m条边&#xff0c;使它变成m1棵树。要求最小化树的直径的最大值。 【题解】 二分答案。$Check$的时候用$DP$&#xff0c;记录当前节点每个儿子的直径$v[i]$&#xff0c;如果$v[i]1>mid$&#xff0c;那么就断掉连向儿子的这条边。如果…

    将原生SQL功能Hibernate到您的Spring Data Repository中

    JPA为您提供NamedNativeQuery以便使用本机SQL。 但是&#xff0c;用法并不方便&#xff0c;特别是当您需要在本机SQL中映射多个实体时。 您必须定义一组SqlResultSetMapping映射&#xff0c;这很容易出错。 对于以前使用过Hibernate本机SQL功能的用户&#xff0c;您会发现它比J…

    daterangepicker双日历插件的使用

    今天主要是由于项目的需要&#xff0c;做了一个daterangepicker双日历插件&#xff0c;做出来的效果如下&#xff1a; 个人感觉这个daterangepicker双日历插件很好用&#xff0c;并且实现起来也不是很麻烦&#xff0c;我是根据它的官方文档去写的&#xff0c;并将Bootstrap也整…

    php 递归展现城市信息,PHP 递归兑现层级树状展现数据

    PHP 递归实现层级树状展现数据?$arr[id],fid > $arr[fid],name > $arr[name],);}// 将数据按照缩进简单排列 见图1function data2arr($tree, $rootId 0, $level 0) {foreach($tree as $leaf) {if($leaf[fid] $rootId) {echo str_repeat( , $level) . $leaf[id] . .…

    牛客网 2018年全国多校算法寒假训练营练习比赛(第五场) H.Tree Recovery-完全版线段树(区间更新、区间求和)...

    H.Tree Recovery时间限制&#xff1a;C/C 1秒&#xff0c;其他语言2秒空间限制&#xff1a;C/C 131072K&#xff0c;其他语言262144K64bit IO Format: %lld链接&#xff1a;https://www.nowcoder.com/acm/contest/77/H来源&#xff1a;牛客网题目描述 You have N integers, A1,…

    面向对象的代码生成方法

    代码生成是减少无聊任务的不健康负担的一种常用方法&#xff0c;这些任务常常使我们急切的代码苦恼。 我见过的许多代码生成框架都使用模板替换重复方法&#xff0c;在该方法中&#xff0c;您可以编写一个模板&#xff0c;以了解生成的代码文件的外观&#xff0c;然后替换某些关…

    t oracle删除吗,Oracle 11g 手工建库与删库

    Oracle 11g 手工建库与删库在前一篇文章中提到阅读Oracle 11gR2 Administrator‘sGuide(文档编号E25494-01)时&#xff0c;简单描述了DDL_LOCK_TIMEOUT参数。在Oracle 11gR2Administrator‘s Guide文档的chapter 2 Creating and Configuring anOracle Database章节时&#xff0…

    oracle连接满报错日志,Oracle归档日志满了导致Oracle连接(ORA-00257)报错处理

    最近一段时间&#xff0c;有收到一台Oracle服务器的连接告警&#xff0c; 刚刚开始还以为是Oracle的监听被关闭导致&#xff0c;结果连上服务器看下Oracle的监听进程正常&#xff0c;自己连接一次发现有报ORA-00257错&#xff0c;又去监控系统中在看下日志再用sqlplus连上Oracl…

    微信登陆超时 重新登录_重新登录:重新登录

    微信登陆超时 重新登录嗨&#xff0c;我再次感到非常高兴&#xff0c;认为日志记录是任何应用程序设计和开发的固有部分。 我是坚强的基础知识的忠实拥护者&#xff0c;以我的拙见&#xff0c;日志记录是任何企业级应用程序中经常被忽略但基本的关键要素之一。 我已经写在此之前…

    HBase错误:ERROR: Can't get master address from ZooKeeper; znode data == null 解决办法

    一、问题背景 使用命令 $ hbase shell 进入hbase的shell之后使用create命令创建表时出现错误&#xff1a;ERROR: Cant get master address from ZooKeeper; znode data null 二、解决方法 检查${HBASE_HOME}/conf/hbase-site.html的属性hbase.rootdir <property><na…

    oracle中OEM证书失效怎么办,安全证书过期怎么办 网站安全证书失效处理【解决方法】...

    安全证书过期怎么办?所谓的网站安全证书是通过在客户端浏览器和Web服务器之间建立一条SSL安全通道保证了双方传递信息的安全性&#xff0c;而且用户可以通过服务器证书验证他所访问的网站是否真实可靠。下面&#xff0c;我们就来看看网站安全证书失效处理方法。一、计算机中的…

    JavaFX缺少的功能调查:表视图

    JavaFX的TableView&#xff08;和TreeTableView&#xff09;赢得了我最近的“ JavaFX缺失功能”调查以及许多后续讨论中&#xff08;尤其是苏黎世JavaFX Meetup小组的成员 &#xff09;中提到最多的控件的价格。 &#xff09;。 我想原因之一是一个简单的事实&#xff0c;即几乎…

    快速幂矩阵快速幂

    快速幂 题目链接&#xff1a;https://www.luogu.org/problemnew/show/P1226 快速幂用了二分的思想&#xff0c;即将\(a^{b}\)的指数b不断分解成二进制的形式&#xff0c;然后相乘累加起来&#xff0c;就是用\(a^{b/2}a^{b/2}\)去求\(a{^b}\)。 例如:\(a^{11}a^{(2^02^12^3)}\)…

    前端项目里常见的十种报错及其解决办法

    错误一&#xff1a;Uncaught TypeError: Cannot set property onclick of nullat operate.js:86图片.png原因&#xff1a;当js文件放在head里面时&#xff0c;如果绑定了onclick事件&#xff0c;就会出现这样的错误&#xff0c;是因为W3School的写法是浏览器先加载完按钮节点才…

    监控oracle数据io,Prometheus监控Oracle数据库

    背景本文简单介绍下&#xff0c;Prometheus如何通过exporters监控Oracle数据库&#xff0c;以及应该注意哪些指标。oracledb_exporteroracledb_exporter是一个连接到Oracle数据库并生成Prometheus metrics的应用程序&#xff0c;设置展示下如何安装和设置oracledb_exporter&…

    默认HotSpot最大直接内存大小

    在我以前的博客文章热点选项中的Java 8改进的文档 &#xff0c;我写的误解围绕热点JVM非标准的默认设置选项 -XX:MaxDirectMemorySize 。 在本文中&#xff0c;我介绍了一种确定HotSpot JVM中“默认”最大直接内存大小的简单方法。 Java启动器的Java 8文档针对-XX:MaxDirectMe…

    window 下 Atom 侧边栏字体大小设置

    在 File 处找到 Settings 点击找到 Themes 点击找到 your stylesheet 点击在 .tree-view 处设置即可, (按照 css 样式来写即可保存生效)。转载于:https://www.cnblogs.com/zhourongcode/p/8521317.html