socialite a python-integrated query language for big data...

44
SociaLite: A Python-Integrated Query Language for Big Data Analysis Jiwon Seo * Jongsoo Park Jaeho Shin Stephen Guo Monica Lam S TANFORD U NIVERSITY M OBI S OCIAL R ESEARCH G ROUP * Intel Parallel Research Lab

Upload: others

Post on 25-Aug-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

SociaLite: A Python-Integrated Query Language for Big Data Analysis

Jiwon Seo *Jongsoo Park Jaeho Shin Stephen Guo Monica Lam

STANFORD UNIVERSITY M O B I S O C I A L R E S E A R C H G R O U P

*Intel Parallel Research Lab

Page 2: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Existing platforms are … § Not fast enough (not network bandwidth) §  Too difficult (low-level primitives) §  Too many (sub) frameworks § Graph analysis § Data mining § Machine learning

Why another Big Data Platform?

Page 3: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

SociaLite is a high-level query language § Compiled to parallel code

§ 1,000x hadoop § Hadoop compatible § Python integration § Designed for graph analysis § Good for data mining & machine learning

Introducing SociaLite

Page 4: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§  Language § Tables § Queries § Python integration § Approximation

§  Analysis algorithms § Shortest paths, PageRank § K-Means, Logistic regression

§  Evaluation § Demo

Outline

1

7

9 10

11

2 5

7

Page 5: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§  Primary data structure in SociaLite §  Column oriented storage §  <type>

§ Primitive types § Object types

Distributed In-Memory Tables

Table (<type> cx, …, (<type> cy, … (<type> cz…))).

Page 6: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Distributed In-Memory Tables Foo(int x, int y).

1 9 1 10 2 5

Bar[int x](int y).

Foo(int x, (int y)).

9 7

1 2 9

1 2 3 4 9 7

2 8

Machine 1 Machine 2

Bar[int x:0..10](int y).

Machine 1 Machine 2

1 2 2 8 3 4

9 7

9 10

5

7

Page 7: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Table options §  indexby <column> § sortby <column> § multiset

Column options § range §  (distributed) partition

Distributed In-Memory Tables

Foo(int x, int y) indexby x. Foo(int x, int y) sortby x. Foo(int x, int y) multiset.

Foo(int x:0..100, int y). Foo[int x](int y).

Page 8: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Rules (Queries)

Foo(a, c) :- Bar(a, b), Qux(b, c). Rule head Rule body

Page 9: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Rules

Foo(a, c) :- Bar(a, b), Qux(b, c).

1 2 1 3 8 4 8 7 9 11

2 9 2 10 5 4 10 7 11 9

Bar Qux Foo

Page 10: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Rules

Foo(a, c) :- Bar(a, b), Qux(b, c).

1 2 1 3 8 4 8 7 9 11

2 9 2 10 5 4 10 7 11 9

1 9 1 10

Bar Qux Foo

Page 11: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Rules

Foo(a, c) :- Bar(a, b), Qux(b, c).

1 2 1 3 8 4 8 7 9 11

2 9 2 10 5 4 10 7 11 9

1 9 1 10 9 9

Bar Qux Foo

Page 12: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Distributed Execution Foo[int a](int b). Bar[int a](int b). Qux[int a](int b). Foo(a, c) :- Bar(a, b), Qux(b, c).

1 2 Bar

2 9 Qux 1 9

Qux

Foo

Bar

Foo

Machine 1 Machine 2

join

transfer 1 9

Page 13: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Distributed Execution Foo[int a](int b). Bar[int a](int b). Qux[int a](int b). Foo(a, c) :- Qux(b, c), Bar(a, b).

1 2 Bar

2 9 Qux Qux

Foo

Bar

Foo

Machine 1 Machine 2

1 9

Page 14: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Aggregation

Foo(a, $min(c)) :- Bar(a, b), Qux(b, c).

The $min aggregate function is applied to tuples in Foo having the same first column value.

§  Built-in aggregate functions § min, max, sum, avg, argmin

§ User-defined functions §  in Java or Python

Page 15: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§ Head table also appears in rule body Foo(a,c) :- Foo(a,b), Bar(b,c). § Semantics – rule executed repeatedly until no changes to Foo

Recursive Rules

Page 16: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Recursive Rules

`Edge(int s, (int t, double len)) indexby s. Path(int n, double dist) indexby n. ` `Path(t, $min(d)) :- t=$SRC, d=0; :- Path(n, d1), Edge(n, t, d2), d=d1+d2.`

Shortest Path algorithm in recursion + aggregation

Page 17: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§  SociaLite queries in Python code § `Queries are quoted in backtick` à Preprocessing with Python import-hook

§  Python ßà SociaLite § Python functions, variables are accessible in

SociaLite queries § SociaLite tables are readable from Python

Python (Jython) Integration

Page 18: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Python (Jython) Integration

print “This is Python code!” # now we use SociaLite queries below `Foo[int i](String s). Foo(i, s) :- i=42, s=“the answer”.` v=“Python variable” `Foo(i, s) :- i=43, s=$v.` @returns(str) def func(): return “Python func” `Foo(i, s) :- i=44, s=$func().` for i, s in `Foo(i, s)`: print i, s

Page 19: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

CPython Integration

§  JyNI – Jython Native Interface § Stefan Richthofer § http://jyni.org

§  To support CPython extensions in Jython § NumPy, SciPy, Pandas, etc

§  Tkinter works on Jython

Page 20: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Approximate Computation §  Bloom Filter, FM Sketch

BloomFilter §  Bitmap-based set §  Quickly check set membership à  false positives, but no false negatives §  In SociaLite, useful to store large intermediate

results approximately

Approximation

hash1

hash3

hash2

Page 21: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Approximation w/ Bloom Filter

Foaf(i, ff) :- Friend(i, f), Friend(f, ff). LocalCount(i, $inc(1)) :- Foaf(i, ff), Attr(ff, “Some Attr”).

Page 22: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Approximation w/ Bloom Filter

Foaf(i, ff) :- Friend(i, f), Friend(f, ff). LocalCount(i, $inc(1)) :- Foaf(i, ff), Attr(ff, “Some Attr”).

(2nd column of Foaf table is represented with a Bloom filter)

Page 23: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Approximation w/ Bloom Filter

Foaf(i, ff) :- Friend(i, f), Friend(f, ff). LocalCount(i, $inc(1)) :- Foaf(i, ff), Attr(ff, “Some Attr”).

(2nd column of Foaf table is represented with a Bloom filter)

Exact Approximation Comparison Exec time (min) 28.9 19.4 32.8% faster Memory usage(GB) 26.0 3.0 11.5% usage Accuracy(<10% error) 100.0% 92.5%

* LiveJournal (4.8M nodes, 68M edges)

Page 24: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§ Graph algorithms § Shortest Paths § PageRank

§ Data mining/machine learning algorithms § K-Means Clustering § Logistic regression

Analysis Algorithms

Page 25: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§  Shortest Path

Graph Algorithm

`Edge(int s, (int t, double len)) indexby s. Path(int n, double dist) indexby n. ` `Path(t, $min(d)) :- t=$SRC, d=0; :- Path(n, d1), Edge(n, t, d2), d=d1+d2.`

Page 26: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§  PageRank

Graph Algorithm

`Rank(n, 0, r) :- Node(n), r=1.0/$N.` for t in range(30): `Rank(pi, $t+1, $sum(r)) :- Node(pi), r=0.15*1.0/$N; :- Rank(pj, $t, r1), Edge(pj, pi), EdgeCnt(pj, cnt), r=0.85*r1/cnt.`

Page 27: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§  PageRank

Graph Algorithm

`Rank(n, 0, r) :- Node(n), r=1.0/$N.` for t in range(30): `Rank(pi, $t+1, $sum(r)) :- Node(pi), r=0.15*1.0/$N; :- Rank(pj, $t, r1), Edge(pj, pi), EdgeCnt(pj, cnt), r=0.85*r1/cnt.`

Page 28: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§  K-Means Clustering

Data Mining Algorithm

for i in range(50): `Center(cid, $i+1, $avg(p)) :- Data(id, p), Cluster(id, $i, c), cid=c.value.` `Cluster(id, $i+1, $argmin(idx, d)) :- Data(id, p), Center(idx, $i+1, a), d=$getDiff(p, a).`

Page 29: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§  Logistic Regression

Data Mining Algorithm

for i in range(0, 100): `Gradient($i, $sum(w)) :- Data(id, p), Weight($i, w1), dot=$dot(w1, p), y=$sigmoid(dot), w = $computeWeights(p, y).` `Weight($i+1, w) :- Weight($i, w1), Gradient($i, g), w=$vecSum (w1, g).`

Page 30: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Benchmark algorithms (graph algorithms) §  Shortest-Paths §  PageRank § Mutual Neighbors § Connected Components §  Finding Triangles § Clustering Coefficients

à  Evaluation on a multi-core & distributed cluster

Evaluation

Page 31: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Input Graph for Multi-Core

Source Size Machine

Friendster 120M nodes 2.5B edges

Intel Xeon E5-2670 16 cores(8+8)

2.60GHz 20MB last-level cache

256GB memory

Page 32: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Parallel Performance (Multi-Core)

PageRank Mutual Neighbors

Connected Components Triangle Clustering Coefficients

Shortest Paths

0 2 4 6 8

10 12 14 16

1 2 4 6 8 10 12 14 16

Spe

edup

ove

r 1

core

Number of Cores

speedup ideal speedup

0 2 4 6 8

10 12 14 16

1 2 4 6 8 10 12 14 16

0 2 4 6 8

10 12 14 16

1 2 4 6 8 10 12 14 16 0 2 4 6 8

10 12 14 16

1 2 4 6 8 10 12 14 16 0 2 4 6 8

10 12 14 16

1 2 4 6 8 10 12 14 16

0 2 4 6 8

10 12 14 16

1 2 4 6 8 10 12 14 16

Page 33: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Input Graph for Distributed Evaluation

Source Size Machine

Synthetic Graph* up to 268M nodes 4.3B edges

(weak scaling)

64 Amazon EC2 Instances Intel Xeon X5570, 8 cores

23GB memory

*RMAT algorithm, Graph 500 Generator

Page 34: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Giraph (Pregel) vs SociaLite

8

32

128

512

2 4 8 16 32 64

Exec

Tim

e (S

ec.)

2

8

32

128

2 4 8 16 32 64

Exec

Tim

e (M

in.)

8

32

128

512

2 4 8 16 32 64

Exec

Tim

e (M

in.)

Clustering Coefficients Triangle Connected Components

40

160

640

2 4 8 16 32 64

Exec

Tim

e (S

ec.)

40

160

640

2 4 8 16 32 64

Exec

Tim

e (S

ec.)

1

2

4

8

16

32

2 4 8 16 32 64

Exec

Tim

e (S

ec.)

Shortest paths PageRank Mutual neighbors # of machines

Page 35: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§ Giraph vs SociaLite (lines of code)

Programmability Comparison

Giraph SociaLite Shortest Paths 232 4

PageRank 146 13

Mutual Neighbors 169 6

Connected Components 122 9

Triangles 181 6

Clustering Coefficients 218 12

Total 1,068 50

à  SociaLite is 20x simpler!

Page 36: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§ Collaboration with Intel Parallel Research Lab*

§ Compared frameworks § SociaLite § Giraph § GraphLab § Combinatorial BLAS

§ Native Implementation in C, assembly – optimal * Navigating the Maze of Graph Analytics Frameworks using Massive Graph Datasets, Satish et al., SIGMOD ‘14

Comparing More Graph Frameworks

Page 37: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§  Benchmark Algorithms § BFS (Breadth First Search) § PageRank § Collaborative Filtering § Triangle

§  Evaluation on Intel cluster – Intel Xeon, 24 cores 2.7GHz, 64GB memory, InfiniBand network

§  Input Graph – up to 512M nodes, 16G edges (weak scaling)

Comparing More Graph Frameworks

Page 38: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§  BFS (Breadth First Search)

Programmability

Lines of Code Development Time

SociaLite 4 1~2 min

Giraph 200 1~2 hours

GraphLab 180 1~2 hours

Combinatorial BLAS 450 a few hours

Native > 1000 > A few months

Page 39: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Distributed Execution – Comparison

0  

1  

10  

100  

1000  

1   4   16   64  

Exec  &me  (sec.)  

Breadth First Search

0.1  

1  

10  

100  

1   4   16   64  

Time  pe

r  iter.  (sec.)  

PageRank

1  

10  

100  

1000  

10000  

1   4   16   64  

Time  pe

r  iter.  (sec.)  

0  

1  

10  

100  

1000  

1   4   16   64  Exec  &me  (sec.)  

Triangle Collaborative Filtering

# of machines

Page 40: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

Distributed Execution – Comparison

0  

1  

10  

100  

1000  

1   4   16   64  

Exec  &me  (sec.)  

Breadth First Search

0.1  

1  

10  

100  

1   4   16   64  

Time  pe

r  iter.  (sec.)  

PageRank

1  

10  

100  

1000  

10000  

1   4   16   64  

Time  pe

r  iter.  (sec.)  

0  

1  

10  

100  

1000  

1   4   16   64  Exec  &me  (sec.)  

Triangle Collaborative Filtering

# of machines

Page 41: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§ Collaboration with LinkedIn § Real-time pattern matching queries § Off-line analysis

§ Discussing collaboration with other companies § Kakao § etc

Work In-Progress

Page 42: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§  20x easier than Giraph §  10x faster than Giraph §  As fast as, or faster than

-  GraphLab, CombBlas § How?

- High-level query interface - Compiler optimizations -  Python integration

Summary

Big Data Analysis

Page 43: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

DBLP (CS bibliography) § Co-authorship graph § vertices: authors (1 million) § edges: co-authorship (10 million)

§ Guido van Rossum’s academic network § How Guido is connected to Armin Rigo (PyPy) Jim Hugunin (Jython, IronPython) § Run shortest-paths from Guido & visualize

Demo

Page 44: SociaLite A Python-Integrated Query Language for Big Data ...pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-06_socialite.pdf · SociaLite is a high-level query language ! Compiled

§ Visit http://socialite.stanford.edu for § Trying out § Participation (Apache v2)

Questions?