ݺߣ

ݺߣShare a Scribd company logo
SWARM @ MOSCOWJS
реактивная синхронизация данных
Виктор Грищенко, ООО «Ситреа»	

17 июля 2014
1 2 3 4 5
atom a1
(Alice's first)
weft: a4 weft: a4b2 weft: a5b2
atom offsets
within yarns
yarn "a"
Alice
yarn "0"
special
yarn "b"
Bob ⌫ x
T e s t
ॐ ‫۝‬
causality relation:
a5 is caused by b2
→
3.3 Ordering of siblings
a b a b a
b
a b
a b
a
b c
c
c
a b ( ) > ( )
ct
Citrea and Swarm: partially ordered op logs in
the browser
Victor Grishchenko
Citrea LLC
victor.grishchenko@gmail.com
25 March 2014
Abstract
Principles of eventual consistency are normally applied in large-
scale distributed systems. I report experiences applying EC in Web
app development. Citrea is a collaborative rich text editor employing
the Causal Trees[4] technology of concurrency/version control (note:
CT is not an OT flavor). CT employs symbol ids and trees and, gener-
ally, belongs to the same family as WOOT, Logoot or Treedoc [1, 3, 2].
CT makes the ids-and-trees approach production-practical by limiting
itself to simple and lightweight algorithms and data structures. Swarm
is a JavaScript object sync library that works in the browser, in real
time. Swarm fully employs client-side storage and works well under in-
termittent connectivity. Swarm employs “pure” op-based model. Our
СИНХРОНИЗАЦИЯ
• кэширование
• оффлайн
• реалтайм
CAP
CRDT
Convergent…
Commutative…
Cloud…
Replicated
Data
Types
A CRDT is a data type whose operations
commute when they are concurrent.
Replicas of a CRDT eventually converge
without any complex concurrency control.
ПРОСТЕНЬКИЙ CRDT
11: Is value1 Æ value2 in semilattice?
12: merge (value1, value2) : payload mergedValue
13: LUB merge of value1 and value2, at any replica
M
mergemerge
M
g(x2)
S
S
source
f(x1)
x3
x1
x2
x merge
M
Figure 4: State-based replication
0 1 4
14 4
4 4
4
M
maxmax
M
x2 := 4
G+A
G+A
x1 := 1
x3
x1
x2
x max
M0
0
0
4
4
4
4 4
Figure 5: Example CvRDT: integer + max
SWARM
SWARM: M OF MVC
SWARM (CODE)
var host = new Swarm.Host('user~ssn');
!
host.connect(‘ws://localhost:8000');
!
var mickey = host.get(‘/Mouse#Mickey’,
function(s,v,o){
mickey.set({
x:100,
y:100
});
});
SWARM + REACT
var SwarmMixin = {
deliver: function (spec,val,source) {	

	

 	

 this.isMounted() && this.forceUpdate();
},	

	

 componentWillMount: function () {
var spec = this.props.spec; 

this.sync = app.host.get(spec); 

this.sync.on('.init',this); 

this.sync.on(this);	

	

 },
componentWillUnmount: function () {

this.sync.off(this);

}
};


React.renderComponent(

MouseTrackApp ({spec:’/Mouse#Mickey’}), 

document.getElementById('mice-container')

);	

get by spec
on/off
http://swarmjs.github.io
http://github.com/gritzko/swarm



@gritzko
@swarm_js

victor.grishchenko@gmail.com
Ad

Recommended

SCaml compiler
SCaml compiler
Jun Furuse
Updates on the Fake Object Pipeline for HSC Survey
Updates on the Fake Object Pipeline for HSC Survey
Song Huang
[Webinar] Scientific Computation and Data Visualization with Ruby
[Webinar] Scientific Computation and Data Visualization with Ruby
Srijan Technologies
Building blocks for aggregate programming of self-organising applications
Building blocks for aggregate programming of self-organising applications
FoCAS Initiative
Clock
Clock
naniix21_3
Byte rotation encryption algorithm
Byte rotation encryption algorithm
Shikha Jain
Byte Rotation Algorithm
Byte Rotation Algorithm
Engr0918
1 storm-intro
1 storm-intro
Md. Shamsur Rahim
NumPy sorting (and dancing and memes): ​ a short review for students​
NumPy sorting (and dancing and memes): ​ a short review for students​
VladimirFadeev4
Comp
Comp
Igor Nigruca
Integrating Xtext and Sirius: Strategies and Pitfalls
Integrating Xtext and Sirius: Strategies and Pitfalls
Cédric Brun
Reactive Extensions for JavaScript
Reactive Extensions for JavaScript
Jim Wooley
How to use tensorflow
How to use tensorflow
hyunyoung Lee
SOA in the cloud with FraSCAti, OW2con11, Nov 24-25, Paris
SOA in the cloud with FraSCAti, OW2con11, Nov 24-25, Paris
OW2
Александр Русаков - TypeScript 2 in action
Александр Русаков - TypeScript 2 in action
MoscowJS
Виктор Розаев - Как не сломать обратную совместимость в Public API
Виктор Розаев - Как не сломать обратную совместимость в Public API
MoscowJS
Favicon на стероидах
Favicon на стероидах
MoscowJS
E2E-тестирование мобильных приложений
E2E-тестирование мобильных приложений
MoscowJS
Reliable DOM testing with browser-monkey
Reliable DOM testing with browser-monkey
MoscowJS
Basis.js - Production Ready SPA Framework
Basis.js - Production Ready SPA Framework
MoscowJS
Контекст в React, Николай Надоричев, MoscowJS 31
Контекст в React, Николай Надоричев, MoscowJS 31
MoscowJS
Верстка Canvas, Алексей Охрименко, MoscowJS 31
Верстка Canvas, Алексей Охрименко, MoscowJS 31
MoscowJS
Веб без интернет соединения, Михаил Дунаев, MoscowJS 31
Веб без интернет соединения, Михаил Дунаев, MoscowJS 31
MoscowJS
Angular2 Change Detection, Тимофей Яценко, MoscowJS 31
Angular2 Change Detection, Тимофей Яценко, MoscowJS 31
MoscowJS
Создание WYSIWIG-редакторов для веба, Егор Яковишен, Setka, MoscowJs 33
Создание WYSIWIG-редакторов для веба, Егор Яковишен, Setka, MoscowJs 33
MoscowJS
Предсказуемый Viewport, Вопиловский Константин, KamaGames Studio, MoscowJs 33
Предсказуемый Viewport, Вопиловский Константин, KamaGames Studio, MoscowJs 33
MoscowJS
Promise me an Image... Антон Корзунов, Яндекс, MoscowJs 33
Promise me an Image... Антон Корзунов, Яндекс, MoscowJs 33
MoscowJS
Регрессионное тестирование на lenta.ru, Кондратенко Павел, Rambler&Co, Moscow...
Регрессионное тестирование на lenta.ru, Кондратенко Павел, Rambler&Co, Moscow...
MoscowJS
"Опыт разработки универсальной библиотеки визуальных компонентов в HeadHunter...
"Опыт разработки универсальной библиотеки визуальных компонентов в HeadHunter...
MoscowJS
"Во все тяжкие с responsive images", Павел Померанцев, MoscowJS 29
"Во все тяжкие с responsive images", Павел Померанцев, MoscowJS 29
MoscowJS

More Related Content

What's hot (6)

NumPy sorting (and dancing and memes): ​ a short review for students​
NumPy sorting (and dancing and memes): ​ a short review for students​
VladimirFadeev4
Comp
Comp
Igor Nigruca
Integrating Xtext and Sirius: Strategies and Pitfalls
Integrating Xtext and Sirius: Strategies and Pitfalls
Cédric Brun
Reactive Extensions for JavaScript
Reactive Extensions for JavaScript
Jim Wooley
How to use tensorflow
How to use tensorflow
hyunyoung Lee
SOA in the cloud with FraSCAti, OW2con11, Nov 24-25, Paris
SOA in the cloud with FraSCAti, OW2con11, Nov 24-25, Paris
OW2
NumPy sorting (and dancing and memes): ​ a short review for students​
NumPy sorting (and dancing and memes): ​ a short review for students​
VladimirFadeev4
Integrating Xtext and Sirius: Strategies and Pitfalls
Integrating Xtext and Sirius: Strategies and Pitfalls
Cédric Brun
Reactive Extensions for JavaScript
Reactive Extensions for JavaScript
Jim Wooley
SOA in the cloud with FraSCAti, OW2con11, Nov 24-25, Paris
SOA in the cloud with FraSCAti, OW2con11, Nov 24-25, Paris
OW2

More from MoscowJS (20)

Александр Русаков - TypeScript 2 in action
Александр Русаков - TypeScript 2 in action
MoscowJS
Виктор Розаев - Как не сломать обратную совместимость в Public API
Виктор Розаев - Как не сломать обратную совместимость в Public API
MoscowJS
Favicon на стероидах
Favicon на стероидах
MoscowJS
E2E-тестирование мобильных приложений
E2E-тестирование мобильных приложений
MoscowJS
Reliable DOM testing with browser-monkey
Reliable DOM testing with browser-monkey
MoscowJS
Basis.js - Production Ready SPA Framework
Basis.js - Production Ready SPA Framework
MoscowJS
Контекст в React, Николай Надоричев, MoscowJS 31
Контекст в React, Николай Надоричев, MoscowJS 31
MoscowJS
Верстка Canvas, Алексей Охрименко, MoscowJS 31
Верстка Canvas, Алексей Охрименко, MoscowJS 31
MoscowJS
Веб без интернет соединения, Михаил Дунаев, MoscowJS 31
Веб без интернет соединения, Михаил Дунаев, MoscowJS 31
MoscowJS
Angular2 Change Detection, Тимофей Яценко, MoscowJS 31
Angular2 Change Detection, Тимофей Яценко, MoscowJS 31
MoscowJS
Создание WYSIWIG-редакторов для веба, Егор Яковишен, Setka, MoscowJs 33
Создание WYSIWIG-редакторов для веба, Егор Яковишен, Setka, MoscowJs 33
MoscowJS
Предсказуемый Viewport, Вопиловский Константин, KamaGames Studio, MoscowJs 33
Предсказуемый Viewport, Вопиловский Константин, KamaGames Studio, MoscowJs 33
MoscowJS
Promise me an Image... Антон Корзунов, Яндекс, MoscowJs 33
Promise me an Image... Антон Корзунов, Яндекс, MoscowJs 33
MoscowJS
Регрессионное тестирование на lenta.ru, Кондратенко Павел, Rambler&Co, Moscow...
Регрессионное тестирование на lenta.ru, Кондратенко Павел, Rambler&Co, Moscow...
MoscowJS
"Опыт разработки универсальной библиотеки визуальных компонентов в HeadHunter...
"Опыт разработки универсальной библиотеки визуальных компонентов в HeadHunter...
MoscowJS
"Во все тяжкие с responsive images", Павел Померанцев, MoscowJS 29
"Во все тяжкие с responsive images", Павел Померанцев, MoscowJS 29
MoscowJS
"AMP - технология на три буквы", Макс Фролов, MoscowJS 29
"AMP - технология на три буквы", Макс Фролов, MoscowJS 29
MoscowJS
"Observable и Computed на пример KnockoutJS", Ольга Кобец, MoscowJS 29
"Observable и Computed на пример KnockoutJS", Ольга Кобец, MoscowJS 29
MoscowJS
«Пиринговый веб на JavaScript», Денис Глазков, MoscowJS 28
«Пиринговый веб на JavaScript», Денис Глазков, MoscowJS 28
MoscowJS
"Доклад не про React", Антон Виноградов, MoscowJS 27
"Доклад не про React", Антон Виноградов, MoscowJS 27
MoscowJS
Александр Русаков - TypeScript 2 in action
Александр Русаков - TypeScript 2 in action
MoscowJS
Виктор Розаев - Как не сломать обратную совместимость в Public API
Виктор Розаев - Как не сломать обратную совместимость в Public API
MoscowJS
Favicon на стероидах
Favicon на стероидах
MoscowJS
E2E-тестирование мобильных приложений
E2E-тестирование мобильных приложений
MoscowJS
Reliable DOM testing with browser-monkey
Reliable DOM testing with browser-monkey
MoscowJS
Basis.js - Production Ready SPA Framework
Basis.js - Production Ready SPA Framework
MoscowJS
Контекст в React, Николай Надоричев, MoscowJS 31
Контекст в React, Николай Надоричев, MoscowJS 31
MoscowJS
Верстка Canvas, Алексей Охрименко, MoscowJS 31
Верстка Canvas, Алексей Охрименко, MoscowJS 31
MoscowJS
Веб без интернет соединения, Михаил Дунаев, MoscowJS 31
Веб без интернет соединения, Михаил Дунаев, MoscowJS 31
MoscowJS
Angular2 Change Detection, Тимофей Яценко, MoscowJS 31
Angular2 Change Detection, Тимофей Яценко, MoscowJS 31
MoscowJS
Создание WYSIWIG-редакторов для веба, Егор Яковишен, Setka, MoscowJs 33
Создание WYSIWIG-редакторов для веба, Егор Яковишен, Setka, MoscowJs 33
MoscowJS
Предсказуемый Viewport, Вопиловский Константин, KamaGames Studio, MoscowJs 33
Предсказуемый Viewport, Вопиловский Константин, KamaGames Studio, MoscowJs 33
MoscowJS
Promise me an Image... Антон Корзунов, Яндекс, MoscowJs 33
Promise me an Image... Антон Корзунов, Яндекс, MoscowJs 33
MoscowJS
Регрессионное тестирование на lenta.ru, Кондратенко Павел, Rambler&Co, Moscow...
Регрессионное тестирование на lenta.ru, Кондратенко Павел, Rambler&Co, Moscow...
MoscowJS
"Опыт разработки универсальной библиотеки визуальных компонентов в HeadHunter...
"Опыт разработки универсальной библиотеки визуальных компонентов в HeadHunter...
MoscowJS
"Во все тяжкие с responsive images", Павел Померанцев, MoscowJS 29
"Во все тяжкие с responsive images", Павел Померанцев, MoscowJS 29
MoscowJS
"AMP - технология на три буквы", Макс Фролов, MoscowJS 29
"AMP - технология на три буквы", Макс Фролов, MoscowJS 29
MoscowJS
"Observable и Computed на пример KnockoutJS", Ольга Кобец, MoscowJS 29
"Observable и Computed на пример KnockoutJS", Ольга Кобец, MoscowJS 29
MoscowJS
«Пиринговый веб на JavaScript», Денис Глазков, MoscowJS 28
«Пиринговый веб на JavaScript», Денис Глазков, MoscowJS 28
MoscowJS
"Доклад не про React", Антон Виноградов, MoscowJS 27
"Доклад не про React", Антон Виноградов, MoscowJS 27
MoscowJS
Ad

Recently uploaded (20)

cybercrime investigation and digital forensics
cybercrime investigation and digital forensics
goverdhankumar137300
AMOR PROHIBIDO MURMURAN POR LAS CALLES PORQUE
AMOR PROHIBIDO MURMURAN POR LAS CALLES PORQUE
GFGLaboratorios
simple-presentationtestingdocument2007.pptx
simple-presentationtestingdocument2007.pptx
ashokjayapal
Topic 1 Foundational IT Infrastructure_.pptx
Topic 1 Foundational IT Infrastructure_.pptx
oneillp100
Internet Download Manager (IDM) 6.42.40 Crack Download
Internet Download Manager (IDM) 6.42.40 Crack Download
Puppy jhon
AWS Basics for non technical people.pptx
AWS Basics for non technical people.pptx
sanjeevkumar123577
Fast Reroute in SR-MPLS, presented at bdNOG 19
Fast Reroute in SR-MPLS, presented at bdNOG 19
APNIC
AI theory work for students to understand the logic
AI theory work for students to understand the logic
areeba15775n
Lecture 3.1 Analysing the Global Business Environment .pptx
Lecture 3.1 Analysing the Global Business Environment .pptx
shofalbsb
Dark Web Presentation - 1.pdf about internet which will help you to get to kn...
Dark Web Presentation - 1.pdf about internet which will help you to get to kn...
ragnaralpha7199
3 years of Quarkus in production, what have we learned - Devoxx Polen
3 years of Quarkus in production, what have we learned - Devoxx Polen
Jago de Vreede
SAP_S4HANA_ChatGPT_Integration_Presentation.pptx
SAP_S4HANA_ChatGPT_Integration_Presentation.pptx
vemulavenu484
Topic 2 - Cloud Computing Basics,,,.pptx
Topic 2 - Cloud Computing Basics,,,.pptx
oneillp100
Timeline Infographics Para utilização diária
Timeline Infographics Para utilização diária
meslellis
ChatGPT A.I. Powered Chatbot and Popularization.pdf
ChatGPT A.I. Powered Chatbot and Popularization.pdf
StanleySamson1
Top Mobile App Development Trends Shaping the Future
Top Mobile App Development Trends Shaping the Future
ChicMic Studios
Quantiuwewe e3er14e we3223 32222 m2.pptx
Quantiuwewe e3er14e we3223 32222 m2.pptx
cyberesearchprof
CBUSDAW - Ash Lewis - Reducing LLM Hallucinations
CBUSDAW - Ash Lewis - Reducing LLM Hallucinations
Jason Packer
NOC Services for maintaining network as MSA.ppt
NOC Services for maintaining network as MSA.ppt
ankurnagar22
DDos Mitigation Strategie, presented at bdNOG 19
DDos Mitigation Strategie, presented at bdNOG 19
APNIC
cybercrime investigation and digital forensics
cybercrime investigation and digital forensics
goverdhankumar137300
AMOR PROHIBIDO MURMURAN POR LAS CALLES PORQUE
AMOR PROHIBIDO MURMURAN POR LAS CALLES PORQUE
GFGLaboratorios
simple-presentationtestingdocument2007.pptx
simple-presentationtestingdocument2007.pptx
ashokjayapal
Topic 1 Foundational IT Infrastructure_.pptx
Topic 1 Foundational IT Infrastructure_.pptx
oneillp100
Internet Download Manager (IDM) 6.42.40 Crack Download
Internet Download Manager (IDM) 6.42.40 Crack Download
Puppy jhon
AWS Basics for non technical people.pptx
AWS Basics for non technical people.pptx
sanjeevkumar123577
Fast Reroute in SR-MPLS, presented at bdNOG 19
Fast Reroute in SR-MPLS, presented at bdNOG 19
APNIC
AI theory work for students to understand the logic
AI theory work for students to understand the logic
areeba15775n
Lecture 3.1 Analysing the Global Business Environment .pptx
Lecture 3.1 Analysing the Global Business Environment .pptx
shofalbsb
Dark Web Presentation - 1.pdf about internet which will help you to get to kn...
Dark Web Presentation - 1.pdf about internet which will help you to get to kn...
ragnaralpha7199
3 years of Quarkus in production, what have we learned - Devoxx Polen
3 years of Quarkus in production, what have we learned - Devoxx Polen
Jago de Vreede
SAP_S4HANA_ChatGPT_Integration_Presentation.pptx
SAP_S4HANA_ChatGPT_Integration_Presentation.pptx
vemulavenu484
Topic 2 - Cloud Computing Basics,,,.pptx
Topic 2 - Cloud Computing Basics,,,.pptx
oneillp100
Timeline Infographics Para utilização diária
Timeline Infographics Para utilização diária
meslellis
ChatGPT A.I. Powered Chatbot and Popularization.pdf
ChatGPT A.I. Powered Chatbot and Popularization.pdf
StanleySamson1
Top Mobile App Development Trends Shaping the Future
Top Mobile App Development Trends Shaping the Future
ChicMic Studios
Quantiuwewe e3er14e we3223 32222 m2.pptx
Quantiuwewe e3er14e we3223 32222 m2.pptx
cyberesearchprof
CBUSDAW - Ash Lewis - Reducing LLM Hallucinations
CBUSDAW - Ash Lewis - Reducing LLM Hallucinations
Jason Packer
NOC Services for maintaining network as MSA.ppt
NOC Services for maintaining network as MSA.ppt
ankurnagar22
DDos Mitigation Strategie, presented at bdNOG 19
DDos Mitigation Strategie, presented at bdNOG 19
APNIC
Ad

Swarm.js: реактивная синхронизация данных — Виктор Грищенко — MoscowJS 13

  • 1. SWARM @ MOSCOWJS реактивная синхронизация данных Виктор Грищенко, ООО «Ситреа» 17 июля 2014
  • 2. 1 2 3 4 5 atom a1 (Alice's first) weft: a4 weft: a4b2 weft: a5b2 atom offsets within yarns yarn "a" Alice yarn "0" special yarn "b" Bob ⌫ x T e s t ॐ ‫۝‬ causality relation: a5 is caused by b2 → 3.3 Ordering of siblings a b a b a b a b a b a b c c c a b ( ) > ( ) ct Citrea and Swarm: partially ordered op logs in the browser Victor Grishchenko Citrea LLC victor.grishchenko@gmail.com 25 March 2014 Abstract Principles of eventual consistency are normally applied in large- scale distributed systems. I report experiences applying EC in Web app development. Citrea is a collaborative rich text editor employing the Causal Trees[4] technology of concurrency/version control (note: CT is not an OT flavor). CT employs symbol ids and trees and, gener- ally, belongs to the same family as WOOT, Logoot or Treedoc [1, 3, 2]. CT makes the ids-and-trees approach production-practical by limiting itself to simple and lightweight algorithms and data structures. Swarm is a JavaScript object sync library that works in the browser, in real time. Swarm fully employs client-side storage and works well under in- termittent connectivity. Swarm employs “pure” op-based model. Our
  • 4. CRDT Convergent… Commutative… Cloud… Replicated Data Types A CRDT is a data type whose operations commute when they are concurrent. Replicas of a CRDT eventually converge without any complex concurrency control.
  • 5. ПРОСТЕНЬКИЙ CRDT 11: Is value1 Æ value2 in semilattice? 12: merge (value1, value2) : payload mergedValue 13: LUB merge of value1 and value2, at any replica M mergemerge M g(x2) S S source f(x1) x3 x1 x2 x merge M Figure 4: State-based replication 0 1 4 14 4 4 4 4 M maxmax M x2 := 4 G+A G+A x1 := 1 x3 x1 x2 x max M0 0 0 4 4 4 4 4 Figure 5: Example CvRDT: integer + max
  • 8. SWARM (CODE) var host = new Swarm.Host('user~ssn'); ! host.connect(‘ws://localhost:8000'); ! var mickey = host.get(‘/Mouse#Mickey’, function(s,v,o){ mickey.set({ x:100, y:100 }); });
  • 9. SWARM + REACT var SwarmMixin = { deliver: function (spec,val,source) { this.isMounted() && this.forceUpdate(); }, componentWillMount: function () { var spec = this.props.spec; 
 this.sync = app.host.get(spec); 
 this.sync.on('.init',this); 
 this.sync.on(this); }, componentWillUnmount: function () {
 this.sync.off(this);
 } }; 
 React.renderComponent(
 MouseTrackApp ({spec:’/Mouse#Mickey’}), 
 document.getElementById('mice-container')
 ); get by spec on/off