SlideShare una empresa de Scribd logo
1 de 25
Distributed Java
map structures
and services
with Redisson
Nikita Koksharov
(Founder of Redisson)
Integration
with
frameworks
LockDistributed
locks and
synchronizers ReadWriteLock RedLockSemaphore
Distributed
collections
… MultiLockFairLock
Map
Set
Multimap
List
Queue
Deque
SortedSet
DelayedQueue
RemoteService
Distributed
services LiveObjectService
ExecutorService
SchedulerService
MapReduce
Service
…
REDISSON OVERVIEW
Spring
Hibernate cache
JCache API
(JSR-107)
Tomcat
Dropwizard metrics
MAP
ConcurrentMap<Integer, MyObject> map = new ConcurrentHashMap<>();
map.put(20, new MyObject("oldobj"));
map.putIfAbsent(20, new MyObject("newobj"));
map.containsKey(1);
REDISSON MAP
ConcurrentMap<Integer, MyObject> map = redisson.getMap("someMap");
map.put(20, new MyObject("oldobj")); // wraps HSET command
map.putIfAbsent(20, new MyObject("newobj")); // wraps LUA-script
map.containsKey(1);
ConcurrentMap.putIfAbsent
LUA SCRIPT IMPLEMENTATION
"if redis.call('hsetnx', KEYS[1], ARGV[1], ARGV[2]) == 1 then "
"return nil; "
"else "
"return redis.call('hget', KEYS[1], ARGV[1]); "
"end;“
// KEYS[1] = map name
// ARGV[1] = map key
// ARGV[2] = map value
REDISSON SHARDED MAP
Redis Node 1
Redis cluster
Map
Shard 1
Map
Shard 2
Redis
Redis master/slave or single
Map
Shard 1
Map
Shard 2
Map
Shard 3
Map
Shard 4
Map
Shard 5
…
Map
Shard 5
Map
Shard 5
Redis Node 2
Map
Shard 3
Map
Shard 4
Redis Node 3
Map
Shard 5
Map
Shard 6
…
REDISSON MAP
WITH LOCAL CACHE
ConcurrentMap<Integer, MyObject> map =
redisson.getLocalCachedMap("someMap");
Read operations are executed about 100x faster
LOCAL CACHED MAP
ENTRY EVICTION POLICY
▸Least Recently Used
▸Least Frequently Used
▸Soft Reference
▸Weak Reference
LOCAL CACHED MAP
ENTRY INVALIDATION POLICY
▸On change
▸On change
+ clears whole cache on reconnect
▸On change
+ clears changed entries only on reconnect
Redisson Node
Redis
(single, master/slave, sentinel, cluster)
Application Node
Redisson
Application Node
Redisson
Application Node
Redisson
workers
Redisson Node
workers
Redisson Node
workers
TASKS EXECUTION ARCHITECTURE
TASKS EXECUTION
WITHOUT REDISSON NODE
Redisson redisson = …
// custom executor workers
redisson.getExecutorService("myExecutor").registerWorkers(16);
// map-reduce workers
redisson.getExecutorService(MAPREDUCE_NAME).registerWorkers(16);
Redis
(single, master/slave, sentinel, cluster)
Application Node
Redisson
Application Node
Redisson
Application Node
Redisson
workers workers workers
WORKERS ON APPLICATION SIDE
TASK DEFINITION / CALLABLE
public class CallableTask implements Callable<MyResult> {
@RInject
private RedissonClient redissonClient;
private String param;
@Override
public MyResult call() throws Exception {
// task body
}
}
TASK DEFINITION / RUNNABLE
public class RunnableTask implements Runnable {
@RInject
private RedissonClient redissonClient;
@Override
public void run() {
// task body
}
}
SUBMITTING TASKS
FOR EXECUTION
// implements java.util.concurrent.ExecutorService
RExecutorService executorService = redisson.getExecutorService("myExecutor");
executorService.submit(new RunnableTask());
// or with parameters
executorService.submit(new RunnableTask(41, "someParam"));
executorService.submit(new CallableTask());
// or with parameters
executorService.submit(new CallableTask(53, "someParam"));
SUBMITTING TASKS
FOR SCHEDULED EXECUTION
// implements java.util.concurrent.ScheduledExecutorService
RScheduledExecutorService es = redisson.getExecutorService("myExecutor");
es.schedule(new CallableTask(), 10, TimeUnit.MINUTES);
// or
es.schedule(new RunnableTask(), 5, TimeUnit.SECONDS);
es.scheduleAtFixedRate(new RunnableTask(), 10, 25, TimeUnit.HOURS);
// or
es.scheduleWithFixedDelay(new RunnableTask(), 5, 10, TimeUnit.HOURS);
SCHEDULING TASKS
WITH CRON EXPRESSION
RScheduledExecutorService es = redisson.getExecutorService("myExecutor");
// uses Quartz cron format
es.schedule(new RunnableTask(), CronSchedule.of("10 0/5 * * * ?"));
// or
es.schedule(new RunnableTask(), CronSchedule.dailyAtHourAndMinute(10, 5));
Map
task
Map
phase* …
MAPREDUCE OVERVIEW
Map
task
Map
task
Map
task
Reduce
task
Reduce
phase …Reduce
task
Reduce
task
Reduce
task
*splits to several tasks and run in parallel
only for RShardedSet and RShardedMap objects
MAPREDUCE
DATA SOURCE EXAMPLE
RMap<String, String> map = redisson.getMap("wordsMap");
map.put(“page1:line1", "Alice was beginning to get very tired");
map.put("page1:line2", "of sitting by her sister on the bank and");
map.put("page1:line3", "of having nothing to do once or twice she");
map.put("page1:line4", "had peeked into the book her sister was reading");
map.put("page1:line5", "but it had no pictures or conversations in it");
map.put("page1:line6", "and what is the use of a book");
map.put("page1:line7", "thought Alice without pictures or conversation");
MAPPER DEFINITION
public class WordMapper implements
RMapper<String, String, String, Integer> {
@Override
public void map(String key, String value,
RCollector<String, Integer> collector) {
String[] words = value.split(" ");
for (String word : words) {
collector.emit(word, 1);
}
}
}
REDUCER DEFINITION
public class WordReducer implements RReducer<String, Integer> {
@Override
public Integer reduce(String word, Iterator<Integer> iter) {
int sum = 0;
while (iter.hasNext()) {
Integer i = (Integer) iter.next();
sum += i;
}
return sum;
}
}
COLLATOR DEFINITION
public class WordCollator implements RCollator<String, Integer, Integer> {
@Override
public Integer collate(Map<String, Integer> result) {
int totalWordsAmount = 0;
for (Integer count : result.values()) {
totalWordsAmount += count;
}
return totalWordsAmount;
}
}
RUNNING MAPREDUCE
RMap<String, String> map = redisson.getMap("wordsMap");
RMapReduce mapReduce = map.mapReduce()
.mapper(new WordMapper())
.reducer(new WordReducer())
.timeout(60, TimeUnit.SECONDS);
// count occurrences of words
Map<String, Integer> wordToNumber = mapReduce.execute();
// count total words amount
Integer totalWordsAmount = mapReduce.execute(new WordCollator());
REDISSON VS
OTHER IMDG OR CACHE SOLUTION
Redisson
+ Redis
Java based IMDG
or cache solution
(hazelcast, ehcache …)
Distributed objects
and services  
Large memory
amount handling  have issues
Fully-managed
service support  
THANK YOU!
http://redisson.org

Más contenido relacionado

La actualidad más candente

Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Databricks
 
"Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo...
"Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo..."Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo...
"Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo...
Lucidworks
 
Optimizing MapReduce Job performance
Optimizing MapReduce Job performanceOptimizing MapReduce Job performance
Optimizing MapReduce Job performance
DataWorks Summit
 
Introducing Riak
Introducing RiakIntroducing Riak
Introducing Riak
Kevin Smith
 

La actualidad más candente (20)

Demystifying flink memory allocation and tuning - Roshan Naik, Uber
Demystifying flink memory allocation and tuning - Roshan Naik, UberDemystifying flink memory allocation and tuning - Roshan Naik, Uber
Demystifying flink memory allocation and tuning - Roshan Naik, Uber
 
Introduction to es6
Introduction to es6Introduction to es6
Introduction to es6
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Node js for beginners
Node js for beginnersNode js for beginners
Node js for beginners
 
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
 
Map Reduce
Map ReduceMap Reduce
Map Reduce
 
Introduction to redis - version 2
Introduction to redis - version 2Introduction to redis - version 2
Introduction to redis - version 2
 
Tuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptxTuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptx
 
Improving Apache Spark Downscaling
 Improving Apache Spark Downscaling Improving Apache Spark Downscaling
Improving Apache Spark Downscaling
 
Introducing Saga Pattern in Microservices with Spring Statemachine
Introducing Saga Pattern in Microservices with Spring StatemachineIntroducing Saga Pattern in Microservices with Spring Statemachine
Introducing Saga Pattern in Microservices with Spring Statemachine
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Map Reduce
Map ReduceMap Reduce
Map Reduce
 
Introduction to Apache Flink - Fast and reliable big data processing
Introduction to Apache Flink - Fast and reliable big data processingIntroduction to Apache Flink - Fast and reliable big data processing
Introduction to Apache Flink - Fast and reliable big data processing
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
"Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo...
"Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo..."Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo...
"Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo...
 
Evening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in FlinkEvening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in Flink
 
Optimizing MapReduce Job performance
Optimizing MapReduce Job performanceOptimizing MapReduce Job performance
Optimizing MapReduce Job performance
 
Reading The Source Code of Presto
Reading The Source Code of PrestoReading The Source Code of Presto
Reading The Source Code of Presto
 
Hadoop YARN
Hadoop YARNHadoop YARN
Hadoop YARN
 
Introducing Riak
Introducing RiakIntroducing Riak
Introducing Riak
 

Similar a RedisConf17 - Distributed Java Map Structures and Services with Redisson

Average- An android project
Average- An android projectAverage- An android project
Average- An android project
Ipsit Dash
 
ArcGIS Server Tips and Tricks, MAC-URISA2010
ArcGIS Server Tips and Tricks, MAC-URISA2010ArcGIS Server Tips and Tricks, MAC-URISA2010
ArcGIS Server Tips and Tricks, MAC-URISA2010
Brian
 
Rule Your Geometry with the Terraformer Toolkit
Rule Your Geometry with the Terraformer ToolkitRule Your Geometry with the Terraformer Toolkit
Rule Your Geometry with the Terraformer Toolkit
Aaron Parecki
 
Demoiselle Spatial Latinoware 2011
Demoiselle Spatial Latinoware 2011Demoiselle Spatial Latinoware 2011
Demoiselle Spatial Latinoware 2011
Rafael Soto
 

Similar a RedisConf17 - Distributed Java Map Structures and Services with Redisson (20)

Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
 
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
 
Average- An android project
Average- An android projectAverage- An android project
Average- An android project
 
Angular2 rxjs
Angular2 rxjsAngular2 rxjs
Angular2 rxjs
 
[JEEConf-2017] RxJava as a key component in mature Big Data product
[JEEConf-2017] RxJava as a key component in mature Big Data product[JEEConf-2017] RxJava as a key component in mature Big Data product
[JEEConf-2017] RxJava as a key component in mature Big Data product
 
Reactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwiftReactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwift
 
10. Kapusta, Stofanak - eGlu
10. Kapusta, Stofanak - eGlu10. Kapusta, Stofanak - eGlu
10. Kapusta, Stofanak - eGlu
 
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.
 
Training: Day Four - Struts, Tiles, Renders and Faces
Training: Day Four - Struts, Tiles, Renders and FacesTraining: Day Four - Struts, Tiles, Renders and Faces
Training: Day Four - Struts, Tiles, Renders and Faces
 
ArcGIS Server Tips and Tricks, MAC-URISA2010
ArcGIS Server Tips and Tricks, MAC-URISA2010ArcGIS Server Tips and Tricks, MAC-URISA2010
ArcGIS Server Tips and Tricks, MAC-URISA2010
 
Mapredtutorial
MapredtutorialMapredtutorial
Mapredtutorial
 
Escape from Hadoop: Ultra Fast Data Analysis with Spark & Cassandra
Escape from Hadoop: Ultra Fast Data Analysis with Spark & CassandraEscape from Hadoop: Ultra Fast Data Analysis with Spark & Cassandra
Escape from Hadoop: Ultra Fast Data Analysis with Spark & Cassandra
 
Rule Your Geometry with the Terraformer Toolkit
Rule Your Geometry with the Terraformer ToolkitRule Your Geometry with the Terraformer Toolkit
Rule Your Geometry with the Terraformer Toolkit
 
RxJS Schedulers - Controlling Time
RxJS Schedulers - Controlling TimeRxJS Schedulers - Controlling Time
RxJS Schedulers - Controlling Time
 
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for XamarinGet the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
 
Testowanie JavaScript
Testowanie JavaScriptTestowanie JavaScript
Testowanie JavaScript
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
RxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrowRxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrow
 
Demoiselle Spatial Latinoware 2011
Demoiselle Spatial Latinoware 2011Demoiselle Spatial Latinoware 2011
Demoiselle Spatial Latinoware 2011
 

Más de Redis Labs

SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
Redis Labs
 
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Redis Labs
 
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
Redis Labs
 
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
Redis Labs
 

Más de Redis Labs (20)

Redis Day Bangalore 2020 - Session state caching with redis
Redis Day Bangalore 2020 - Session state caching with redisRedis Day Bangalore 2020 - Session state caching with redis
Redis Day Bangalore 2020 - Session state caching with redis
 
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020
 
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...
 
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
 
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...
 
Redis for Data Science and Engineering by Dmitry Polyakovsky of Oracle
Redis for Data Science and Engineering by Dmitry Polyakovsky of OracleRedis for Data Science and Engineering by Dmitry Polyakovsky of Oracle
Redis for Data Science and Engineering by Dmitry Polyakovsky of Oracle
 
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020
 
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020
 
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...
 
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...
 
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...Highly Available Persistent Session Management Service by Mohamed Elmergawi o...
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...
 
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
 
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...
 
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
 
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
 
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020
 
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020
 
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...
 
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...
 
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

RedisConf17 - Distributed Java Map Structures and Services with Redisson

  • 1. Distributed Java map structures and services with Redisson Nikita Koksharov (Founder of Redisson)
  • 2. Integration with frameworks LockDistributed locks and synchronizers ReadWriteLock RedLockSemaphore Distributed collections … MultiLockFairLock Map Set Multimap List Queue Deque SortedSet DelayedQueue RemoteService Distributed services LiveObjectService ExecutorService SchedulerService MapReduce Service … REDISSON OVERVIEW Spring Hibernate cache JCache API (JSR-107) Tomcat Dropwizard metrics
  • 3. MAP ConcurrentMap<Integer, MyObject> map = new ConcurrentHashMap<>(); map.put(20, new MyObject("oldobj")); map.putIfAbsent(20, new MyObject("newobj")); map.containsKey(1);
  • 4. REDISSON MAP ConcurrentMap<Integer, MyObject> map = redisson.getMap("someMap"); map.put(20, new MyObject("oldobj")); // wraps HSET command map.putIfAbsent(20, new MyObject("newobj")); // wraps LUA-script map.containsKey(1);
  • 5. ConcurrentMap.putIfAbsent LUA SCRIPT IMPLEMENTATION "if redis.call('hsetnx', KEYS[1], ARGV[1], ARGV[2]) == 1 then " "return nil; " "else " "return redis.call('hget', KEYS[1], ARGV[1]); " "end;“ // KEYS[1] = map name // ARGV[1] = map key // ARGV[2] = map value
  • 6. REDISSON SHARDED MAP Redis Node 1 Redis cluster Map Shard 1 Map Shard 2 Redis Redis master/slave or single Map Shard 1 Map Shard 2 Map Shard 3 Map Shard 4 Map Shard 5 … Map Shard 5 Map Shard 5 Redis Node 2 Map Shard 3 Map Shard 4 Redis Node 3 Map Shard 5 Map Shard 6 …
  • 7. REDISSON MAP WITH LOCAL CACHE ConcurrentMap<Integer, MyObject> map = redisson.getLocalCachedMap("someMap"); Read operations are executed about 100x faster
  • 8. LOCAL CACHED MAP ENTRY EVICTION POLICY ▸Least Recently Used ▸Least Frequently Used ▸Soft Reference ▸Weak Reference
  • 9. LOCAL CACHED MAP ENTRY INVALIDATION POLICY ▸On change ▸On change + clears whole cache on reconnect ▸On change + clears changed entries only on reconnect
  • 10. Redisson Node Redis (single, master/slave, sentinel, cluster) Application Node Redisson Application Node Redisson Application Node Redisson workers Redisson Node workers Redisson Node workers TASKS EXECUTION ARCHITECTURE
  • 11. TASKS EXECUTION WITHOUT REDISSON NODE Redisson redisson = … // custom executor workers redisson.getExecutorService("myExecutor").registerWorkers(16); // map-reduce workers redisson.getExecutorService(MAPREDUCE_NAME).registerWorkers(16);
  • 12. Redis (single, master/slave, sentinel, cluster) Application Node Redisson Application Node Redisson Application Node Redisson workers workers workers WORKERS ON APPLICATION SIDE
  • 13. TASK DEFINITION / CALLABLE public class CallableTask implements Callable<MyResult> { @RInject private RedissonClient redissonClient; private String param; @Override public MyResult call() throws Exception { // task body } }
  • 14. TASK DEFINITION / RUNNABLE public class RunnableTask implements Runnable { @RInject private RedissonClient redissonClient; @Override public void run() { // task body } }
  • 15. SUBMITTING TASKS FOR EXECUTION // implements java.util.concurrent.ExecutorService RExecutorService executorService = redisson.getExecutorService("myExecutor"); executorService.submit(new RunnableTask()); // or with parameters executorService.submit(new RunnableTask(41, "someParam")); executorService.submit(new CallableTask()); // or with parameters executorService.submit(new CallableTask(53, "someParam"));
  • 16. SUBMITTING TASKS FOR SCHEDULED EXECUTION // implements java.util.concurrent.ScheduledExecutorService RScheduledExecutorService es = redisson.getExecutorService("myExecutor"); es.schedule(new CallableTask(), 10, TimeUnit.MINUTES); // or es.schedule(new RunnableTask(), 5, TimeUnit.SECONDS); es.scheduleAtFixedRate(new RunnableTask(), 10, 25, TimeUnit.HOURS); // or es.scheduleWithFixedDelay(new RunnableTask(), 5, 10, TimeUnit.HOURS);
  • 17. SCHEDULING TASKS WITH CRON EXPRESSION RScheduledExecutorService es = redisson.getExecutorService("myExecutor"); // uses Quartz cron format es.schedule(new RunnableTask(), CronSchedule.of("10 0/5 * * * ?")); // or es.schedule(new RunnableTask(), CronSchedule.dailyAtHourAndMinute(10, 5));
  • 18. Map task Map phase* … MAPREDUCE OVERVIEW Map task Map task Map task Reduce task Reduce phase …Reduce task Reduce task Reduce task *splits to several tasks and run in parallel only for RShardedSet and RShardedMap objects
  • 19. MAPREDUCE DATA SOURCE EXAMPLE RMap<String, String> map = redisson.getMap("wordsMap"); map.put(“page1:line1", "Alice was beginning to get very tired"); map.put("page1:line2", "of sitting by her sister on the bank and"); map.put("page1:line3", "of having nothing to do once or twice she"); map.put("page1:line4", "had peeked into the book her sister was reading"); map.put("page1:line5", "but it had no pictures or conversations in it"); map.put("page1:line6", "and what is the use of a book"); map.put("page1:line7", "thought Alice without pictures or conversation");
  • 20. MAPPER DEFINITION public class WordMapper implements RMapper<String, String, String, Integer> { @Override public void map(String key, String value, RCollector<String, Integer> collector) { String[] words = value.split(" "); for (String word : words) { collector.emit(word, 1); } } }
  • 21. REDUCER DEFINITION public class WordReducer implements RReducer<String, Integer> { @Override public Integer reduce(String word, Iterator<Integer> iter) { int sum = 0; while (iter.hasNext()) { Integer i = (Integer) iter.next(); sum += i; } return sum; } }
  • 22. COLLATOR DEFINITION public class WordCollator implements RCollator<String, Integer, Integer> { @Override public Integer collate(Map<String, Integer> result) { int totalWordsAmount = 0; for (Integer count : result.values()) { totalWordsAmount += count; } return totalWordsAmount; } }
  • 23. RUNNING MAPREDUCE RMap<String, String> map = redisson.getMap("wordsMap"); RMapReduce mapReduce = map.mapReduce() .mapper(new WordMapper()) .reducer(new WordReducer()) .timeout(60, TimeUnit.SECONDS); // count occurrences of words Map<String, Integer> wordToNumber = mapReduce.execute(); // count total words amount Integer totalWordsAmount = mapReduce.execute(new WordCollator());
  • 24. REDISSON VS OTHER IMDG OR CACHE SOLUTION Redisson + Redis Java based IMDG or cache solution (hazelcast, ehcache …) Distributed objects and services   Large memory amount handling  have issues Fully-managed service support  

Notas del editor

  1. Hi, my name is Nikita. I’m a founder of Redisson project. And I would like to give you brief overview of Java map structures and services with Redisson
  2. Redisson is a Redis based Data Grid which offers you all necessary things required to create distributed application on Java. It offers distributed locks and synchronizers: FairLock, ReadWriteLock, Semaphore, RedLock, MultiLock. Distributed collections: Map, Multimap, Queues, SortedSet and many more. Distributed services and provides integration with frameworks like Spring, Hibernate, Tomcat and also implements JCache API We will have a look more closely at Map structures, Executor, Scheduler and MapReduce services.
  3. Map is most popular data structure in Java and here is a typical usage of map:
  4. If you want to change you code to achieve the same with a Redis hash, the only changes you should do is to create the map using Redisson. Redisson maps methods directly to Redis commands. In this example “put” method implemented using HSET command.
  5. But putIfAbsent method implemented using lua script. Redisson heavily relies on lua scripts. Because lua script is fast, executes atomically and allows to create complex execution flow. This lua script uses only two Redis commands inside.
  6. Redisson provides sharded version of Map structure. This object splitted to multiple shards. Shards amount is configurable. If Redisson connected to Redis Cluster each Redis node will get approximately equal amount of shards if Redis nodes have equal amount of slots.
  7. Another map implementation provided by Redisson is LocalCachedMap object. This object maintains the local cache or so called near cache. This type of map structure is very useful in cases when map used mainly for read operations or network round trips is undesirable. Read operations with local cache are executed about 100 times faster in comparison with usual map.
  8. Since map stored in Redis it could have enormous amount of entries. So, eviction policy could be applied for local cache. Few options are available: Least Recently Used, Least Frequently Used eviction policies which are well known. Soft and Weak reference policies evicts map entries during garbage collection process.
  9. In distributed application any amount of Local Cached Map instances may be used and data could be change through each of them. To maintain actual data in local cache Redisson offers invalidation policies: On change policy invalidates corresponding Local Cache entry across all instances if it has changed in Redis. This algorithm implemented using publish subscribe. Each of Local Cached Map instances subscribes to common channel and listen for message which always published if map entry has changed. So, corresponding map entry is deleted from local cache during invalidation message handling. Next policy is the same as the first one, but also clears cache in case of any reconnection to Redis. And the last policy also maintains map entry changes log. With last policy each time when map entry has changed Redisson does two things: Publishes message to common channel and makes a log record about entry change. These invalidation log records are loaded each time once the connection to Redis has been reconnected. Invalidation log records are stored for last 10 minutes by default. In this way log won’t grow continuously.
  10. Let’s move to tasks execution. Redisson has two parts: Redisson client itself and Redisson Node used for tasks running. Redisson client run on application side. Redisson Node run in standalone mode. Each Redisson Node has configurable amount of workers. Workers are used to execute tasks submitted through Redisson client. All Redisson Nodes are stateless and tasks are stored in Redis until the moment of execution. And of course Redisson Nodes require some actions to deploy, run and maintain. In some cases it would be nice to have workers right on application side.
  11. Redisson allows to do it with single line of code.
  12. Some Redisson users run more than thousand instances of Redisson in production and therefore such approach could be quite effective in terms of computing power utilization.
  13. Let’s consider code examples. Redisson uses standard Runnable and Callable interfaces to define tasks. Each task may have own fields to define parameters during task submission. RedissonClient instance will be injected automatically if field has RedissonClient type and marked with RInject annotation. This provides access to all Redisson’s objects.
  14. Same rules applied to Runnable task
  15. It's pretty easy to submit a task since Redisson service already implements familiar ExecutorService interface from java.util.concurrent package. Each task could have any amount of parameters passed through task’s constructor or setter methods.
  16. Scheduled tasks are submitted using scheduler service which implements ScheduledExecutorService interface from java.util.concurrent package. Tasks could be scheduled for one time execution or scheduled for multiple executions with defined fixed rate or fixed delay between each execution.
  17. Tasks scheduler service allows developer to define more complex scheduling using cron expressions. They fully compatible with Quartz cron format.
  18. The next major feature is a MapReduce framework. It is used to process large amount of data across many Redisson Node. Redisson offers MapReduce support for various objects like Set, Map, SortedSet, List and many more. Map and reduce phases are main parts of MapReduce framework. If you use SharedMap or ShardedSet as data source. Then map phase will be splitted into many subtasks and running in parallel. In this case each subtask works only with own part of map or set. For other objects Map phase is always executed as a single task. Reduce phase is always run in parallel because intermediate values produced during map phase are stored in sharded store which passed to Reduce tasks.
  19. Let’s consider an example how to count words amount in a book using MapReduce. First we need to populate collection with data. In our example we will use Map and a few first lines from the first chapter of “Alice in wonderland” book.
  20. Before MapReduce execution we should define two objects: Mapper and Reducer. Mapper object is used to produce intermediate values and store them into Redis using Collector object. This mapper example applied to each Map entry and split value by space to separate words.
  21. Reducer object handles intermediate values produced during map phase. In our example it’s a word itself and word occurrences amount collection. This Reducer example calculates the total sum for each word.
  22. Collator object is an optional object and used only when result of MapReduce process should be a single object. In our case it’s a total amount of words.
  23. This code example shows how to run mapreduce task with objects provided on previous slides. Each collection object has `mapReduce` method which exposes API for mapper, reducer and timeout definition. Execute methods are used to run Map Reduce process itself.
  24. How does Redisson compare with other in-memory data grids or cache solutions. Some users has successfully moved away from such products like Hazelcast and ehcache. Because of few reasons: Correct large memory amount handling (we all know that Redis can manage with hundreds of gigabytes of RAM on single machine) Availability of fully managed services like AWS Elasticache, Azure Cache and so on. Such services offers full automation, support and management of Redis, so developers can focus on their applications and not maintaining their databases.