Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 ·...

31
© GMV, 2016 Propiedad de GMV Todos los derechos reservados PYTHON Y FLINK Madrid Python Meetup

Transcript of Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 ·...

Page 1: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

© GMV, 2016 Propiedad de GMV

Todos los derechos reservados

PYTHON Y FLINKMadrid Python Meetup

Page 2: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 2

ÍN

DIC

E INTRODUCCIÓN

APACHE FLINK

EXPERIENCIA PYTHON

CONCLUSIONES

Page 3: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

¿Q

UIÉN

ES

S

OM

OS

?

GM

V

Page 4: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 4

UN GRUPO TECNOLÓGICO GLOBAL

Grupo multinacional tecnológico

Fundado en

1984

Capital privado

Sede principal en España (Madrid)

Oficinas en 10 países

Más de 1.100 empleados

Origen vinculado al sector espacial y defensa

Aeronáutica, Espacio, Defensa, Seguridad, Sanidad, Transporte,

Banca y finanzas, y Tecnologías de la Información y la Comunicación

Ingeniería, desarrollo e integración de

sistemas, software, hardware, servicios y

productos especializados

QUIÉNES SOMOS

Page 5: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

IN

TR

OD

UC

CIÓ

N

Page 6: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 8

ACLARACIONESINTRODUCCIÓN

Apache Flink no es un servidor web ni un jefe indio

No vamos a contar palabras

¿Qué sabéis de Big Data?

Page 7: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 9

MADUREZ DEL BIGDATA¿POR QUÉ APACHE FLINK?

Descartar

Almacenar

Procesar

Streaming

Page 8: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 10

ARQUITECTURA TÍPICA¿POR QUÉ APACHE FLINK?

Data adquisition

Stream Processing Serving DB

• Es común almacenar también la información en crudo

• La base de la arquitectura suele ser un clúster con HDFS

Page 9: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 11

DESPLIEGUE¿POR QUÉ APACHE FLINK?

W1W2

W3

W4

Wn

M1

Clúster de HDFS + Flink

K1 K2 Kn

Clúster de Kafka

C3C1 C2

C5C4 C6

Clúster de Cassandra

W5W6

Page 10: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

¿P

OR

QU

É

AP

AC

HE

FLIN

K?

Page 11: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 13

APACHE FLINK¿POR QUÉ APACHE FLINK?

El core de Flink es un motor de procesamiento de flujosde datos en streaming.

Proporciona distribución de los datos, comunicación y toleranciaa fallos para realizarcomputación distribuida con streams de datos.

Sobre ese core se handesarollado dos API y variaslibrerías en Scala, Java y Python

Page 12: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 14

VENTANASFLINK: CARACTERÍSTICAS DIFERENCIADORAS

5 2 6 3 7 5 3 8 2 1 9 4

5 2 6 3 7 5 3 8 2 1 9 4

5 2 6 3 7 5 3 8 2 1 9 4

5 2 6 3 7 5 3 8 2 1 9 4

Ventanas temporales

Ventanas deslizantes

16 23 16

16 21 23 14 16

1s2s

stream.timeWindowAll(Time.seconds(1)).

sum();

stream.timeWindowAll(Time.seconds(1),T

ime.milliseconds(500)).sum();

Page 13: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 15

(A,5) (A,6) (A,5) (A,1)

VENTANAS POR CLAVEFLINK: CARACTERÍSTICAS DIFERENCIADORAS

(A,5) (B,2) (A,6) (C,3) (C,7) (A,5) (B,3) (C,8) (B,2) (A,1) (C,9) (B,4)

Ventanas fijas por clave

1s2s

(B,2) (B,3) (B,2) (B,4)

(C,3) (C,7) (C,8) (C,9)

(A,5) (A,6) (A,5) (A,1)

(B,2) (B,3) (B,2) (B,4)

(C,3) (C,7) (C,8) (C,9)

(A,11)(B,2)(C,3) (A,5)(B,3)(C,15) (A,1)(B,6)(C,9)

(A,11)(B,5) (C,10) (A,6) (C,17) (B,6)

Ventanas por número de elementos

stream.keyBy(0).timeWindow

(Time.seconds(1)).sum(1)

stream.keyBy(0).countWindow(

2).sum(1)

Page 14: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 16

TRIGGERS Y EVICTORSDATASTREAM API

5 2 9 9 7 0 3 8 2 A 9 4

20 18

Pueden cancelar el procesado de los elementos de una ventana

Permiten adelantar el procesado de una ventana

5 2 9 9 7 -1 3 8 2 1 9 4

25 18 16

Podemos controlar los elementos que llegan de las ventanas antes de evaluarlos

Triggers

Evictors

7 3 8

Page 15: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 17

EL TIEMPO ES IMPORTANTEDATASTREAM API

¿Qué tiempo utilizar para construir las ventanas?

El momento en el que se generó el evento

El momento en que se recibe el evento

El momento en que se procesa el evento

Flink maneja relojes diferentes para cada uno de ellos

Page 16: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 18

RENDIMIENTOCOMPARATIVA

• Lo deseable es mantener un alto caudal con una latencia baja

• Flink permite ajustar los tamaños de los buffers internos para aumentar el caudal a costa de aumentar la latencia y viceversa.

Page 17: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 19

FUNCIONALIDADESCOMPARATIVA

Streaming “true” mini batches “true”

API low-level high-level high-level

Fault tolerance tuple-level ACKs RDD-based (lineage) coarse checkpointing

State not built-in external internal

Exactly once at least once exactly once exactly once

Windowing not built-in restricted flexible

Latency low medium low

Throughput medium high high

Page 18: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

EX

PER

IEN

CIA

C

ON

PY

TH

ON

Page 19: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 21

SEGÚN LA DOCUMENTACIÓNEXPERIENCIA CON PYTHON

La mayoría de las API no están disponibles.

¡¡No está disponible la API para Streams!!

El API para procesado en batchtiene todas las operaciones (alguna más que en scala)

Los conectores de E/S son muchos menos y con menos opciones

Page 20: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 22

PRUEBA BÁSICAEXPERIENCIA CON PYTHON

class Adder(GroupReduceFunction):

def reduce(self, iterator, collector):

count, event = iterator.next()

count += sum([x[0] for x in iterator])

collector.collect((event, count))

if __name__ == "__main__":

output_file = 'out.txt'

env = get_environment()

data =

env.read_csv("/home/jordi/Development/python-

flink/final-dataset.csv",\

(INT, STRING, STRING, STRING, STRING, STRING,

STRING, STRING, BOOL, BOOL, INT, INT, INT, INT,

STRING, INT, INT, STRING, STRING, FLOAT, FLOAT,

STRING))

data \

.map(lambda x: (1, x[5])) \

.group_by(1) \

.reduce_group(Adder()) \

.map(lambda x: 'Event: %s. Freq: %s' % (x[0],x[1]))\

.write_text(output_file,write_mode=WriteMode.OVERWRITE)

env.execute(local=True)

El rendimiento es más bajo que el mismo programa en scala.

Levanta un intérprete Python que envía el código al core de Flink

Page 21: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 23

POCA ACIVIDADEXPERIENCIA CON PYTHON

El último commit de la parte de Python fue hace varios meses:

En proporción, hay muy poco código Python:

Page 22: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 24

CONCLUSIONESEXPERIENCIA CON PYTHON

Page 24: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

BA

CK

UP

S

LID

ES

GM

V

Page 25: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 51

TERASORTPERFORMANCE

Terasort es una prueba para medir el rendimiento de tecnologías BigData. Se trata de ordenar 1 Tb de datos (o más) en el menor tiempo posible

http://eastcirclek.blogspot.com.es/2015/06/terasort-for-spark-and-flink-with-range.html

Page 26: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 52

TERASORTPERFORMANCE

http://eastcirclek.blogspot.com.es/2015/06/terasort-for-spark-and-flink-with-range.html

Page 27: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 53

STREAMING - YAHOOPERFORMANCE

https://yahooeng.tumblr.com/post/135321837876/benchmarking-streaming-computation-engines-at

The job of the benchmark is to read various JSON events from Kafka, identify the relevant events, and store a windowed count of relevant events per campaign into Redis.

Page 28: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 54

STREAMING - YAHOOPERFORMANCE

https://yahooeng.tumblr.com/post/135321837876/benchmarking-streaming-computation-engines-at

Page 29: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 55

STREAMING - YAHOOPERFORMANCE

https://yahooeng.tumblr.com/post/135321837876/benchmarking-streaming-computation-engines-at

Page 30: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 56

CONSTRUCCIÓN DE VENTANASVENTANAS

http://data-artisans.com/how-apache-flink-enables-new-streaming-applications-part-1/

Page 31: Madrid Python Meetup PYTHON Y FLINK › 13310742 › PresentacionApacheF... · 2016-07-12 · Madrid Python Meetup 2016/03/10 Página 4 UN GRUPO TECNOLÓGICO GLOBAL Grupo multinacional

Madrid Python Meetup 2016/03/10 Página 57

CONSTRUCCIÓN DE VENTANASVENTANAS