77
@pingtimeout #FailAtBenchs Comment rater ses benchmarks ? Pierre Laporte Ingénieur performances - Datastax @pingtimeout [email protected]

How to fail at benchmarking?

Embed Size (px)

Citation preview

Page 1: How to fail at benchmarking?

@pingtimeout#FailAtBenchs

Comment rater ses benchmarks ?

Pierre Laporte Ingénieur performances - Datastax

@pingtimeout [email protected]

Page 2: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Agenda

• Intro

• Pourquoi cette session ?

• Comment se planter ?

• Que mesurer ?

• Comment mesurer ?

• « Coordinated Omission » ?

• Quel état d’esprit ?

Page 3: How to fail at benchmarking?

@YourTwitterHandle@YourTwitterHandle@pingtimeout#FailAtBenchs

Intro

Page 4: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Page 5: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Cassandra

• NoSQL

• Scalabilité linéaire

• Toujours disponible

Page 6: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Datastax Enterprise (DSE)• Plateforme complète

• Certifiée

• Sécurisée

• Search (Apache Solr)

• Analytics (Hadoop, Spark)

• Simplicité opérationnelle (OpsCenter)

Page 7: How to fail at benchmarking?

@YourTwitterHandle@YourTwitterHandle@pingtimeout#FailAtBenchs

Pourquoi ce talk ?

Page 8: How to fail at benchmarking?

@pingtimeout#FailAtBenchs

I have not failed, I have just found 10,000 ways that won't work.

- Thomas Edison

Page 9: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Progresser

Faire des erreursTrouver des solutions

Ne pas blâmer

Page 10: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Benchmarks

Page 11: How to fail at benchmarking?

@YourTwitterHandle@YourTwitterHandle@pingtimeout#FailAtBenchs

Comment se planter ?

Page 12: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Exemple

• Bench d’une API REST : POST /login

• 100.000 logins

• 1 utilisateur

• Temps de réponse de chaque login

• Mesure dès le premier résultat

• Une exécution (longue)

• Sur un portable de dev

• Moyenne des résultats

• Projection utilisation CPU <=> Capacité restante

Page 13: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Un problème ?

Page 14: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Caches

• « 100.000 logins d’un unique utilisateur »

• Caches CPU (L1, L2, L3, …)

• TLB

• Cache de Base de Données

• Cache Hibernate (query, L2, …)

• …

Page 15: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Précision d'horloge

• « Temps de réponse de chaque login »

• login ~> 5ms

• System.currentTimeMillis() ~> 1ms

• ±1 <=> ±20%

• System.nanoTime() "provides nanosecond precision, but not necessarily nanosecond resolution »

• Source: Javadoc

Page 16: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Temps de chauffe

• « Mesure dès le premier résultat »

• Chargement des classes

• Profiling du code

• Optimisations (Inlining, compilation, élimination de locks, …)

Page 17: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Confiance dans les résultats

• « Une exécution (longue) »

• Bruit de fond ?

• Compétition ?

• Quelle confiance dans les mesures ?

Page 18: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

• « Sur un portable de dev »

Environnement

Page 19: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

• « Sur une seule machine »

Environnement

Page 20: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Métriques

• « Moyenne des résultats »

Page 21: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Projection de capacité

• Utilisation CPU ≈ 50%

• Capacité restante ≈ … ?

Page 22: How to fail at benchmarking?

@YourTwitterHandle@YourTwitterHandle@pingtimeout#FailAtBenchs

Que mesurer ?

Page 23: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Moyenne

• Supprimer les points gênants

• « Moyenne de deux nombres » = … ?

• Pourquoi l’utilise-t-on ?

• Est-ce suffisant ?

Page 24: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Métriques utiles

• Histogramme

• Centiles

• 90ème

• 95ème

• 99ème

• …

• Maximum

Page 25: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Combien de 9 ?

• 99% ?

• 99,99% ??

• Ça dépend.

• Pour 500 utilisateurs

• 99% signifie… ?

Page 26: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Combien de 9 ?

• Si 1.000.000 utilisateurs

• 99% signifie… ?

• 10.000 utilisateurs.

Page 27: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Comment font les autres ?

• 5.000.000 joueurs simultanés

• 12.000.000 par jour

• 67.000.000 par mois• Quels centiles mesurer ?

Page 28: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Maximum

• « Boarf, surement un timeout, on peut l’ignorer »

• Random dev devant un temps de réponse de 60s

• Acceptable ?

• Temps réel ?

• Jeux vidéo ?

• Appli mobile ?

Page 29: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Genèse d’un benchmark

• Une question bien spécifique

• Des exigences précises

• Exemple

• Site de e-commerce

• « Avec mes 5 serveurs d’application, 20.000 articles en base, et 1.000 clients simultanés, est-ce que la commande d’article prend moins de 50ms en moyenne, 100ms une fois sur 10 et 300ms au pire ? »

Page 30: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Environnement

• « Avec mes 5 serveurs d’application, 20.000 articles en base, et 1.000 clients simultanés, est-ce que la commande d’article prend moins de 50ms en moyenne, 100ms une fois sur 10 et 300ms au pire ? »

• POC:

• TomEE

• Glassfish

• Weblogic

Page 31: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Charge

• « Avec mes 5 serveurs d’application, 20.000 articles en base, et 1.000 clients simultanés, est-ce que la commande d’article prend moins de 50ms en moyenne, 100ms une fois sur 10 et 300ms au pire ? »

Page 32: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Exigences

• « Avec mes 5 serveurs d’application, 20.000 articles en base, et 1.000 clients simultanés, est-ce que la commande d’article prend moins de 50ms en moyenne, de 100ms une fois sur 10 et de 300ms au pire ? »

Page 33: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Épilogue d’un benchmark

• Réponse obtenue

• Satisfaisante… ou pas.

• Résultats Contextuels

• Environnement

• Charge

• Contraintes

• Compromis

Page 34: How to fail at benchmarking?

@YourTwitterHandle@YourTwitterHandle@pingtimeout#FailAtBenchs

Vérités statistiques

Page 35: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

99ème centile en moyenne

• Application typique en 2012

• 100 « Web objects »/page

• ≈ 100 requêtes HTTP/page

• Probabilité d’éviter le 99ème centile ?

• 0.99n, sur n requêtes

• 0.99100 ≈ 36.6%

Page 36: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

La loi Normale

• Le client dit :

• Moyenne = 100ms

• Écart type = 20ms

• Médiane = 120ms

• Maximum = 1s

• Quel est le 99% ?

Page 37: How to fail at benchmarking?

@YourTwitterHandle@YourTwitterHandle@pingtimeout#FailAtBenchs

Aucune idée.

Page 38: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Quartet d'Anscombe

Page 39: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Loi Normale et latence

• Le temps de réponse ne suit pas une distribution Normale.

• Dropwizard metrics :

Page 40: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Loi Normale et latence

• Remplacer metrics par HdrHistogram

• Plage de valeurs

• Précision

• Empreinte mémoire constante

• http://hdrhistogram.github.io/HdrHistogram/

Page 41: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Représentation

Page 42: How to fail at benchmarking?

@YourTwitterHandle@YourTwitterHandle@pingtimeout#FailAtBenchs

Puzzles

Page 43: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Puzzler #1

• Un problème ?

Page 44: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Puzzler #1 complet

Page 45: How to fail at benchmarking?

@pingtimeout#FailAtBenchs

Page 46: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Puzzler #1 - nouvel essai

• -XX:+AggressiveOpts

• Qui connaît ?

• Qu’est-ce que cela fait ?

Page 47: How to fail at benchmarking?

@pingtimeout#FailAtBenchs

Page 48: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Aggressive Opts ?

• Augmente le pool de Fixnum de 128 à … ?

• À vous de trouver

• Astuces

• set_aggressive_opts_flags() dans arguments.cpp

• java -XX:+PrintFlagsFinal

• C’est presque tout.

Page 49: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Puzzler #2 - QCM

• Que fait ce code ?

1. Il pousse un juron2. Il ne fait pas ce qu’on pense3. Il bench Hotspot4. Il crée environ 10.000 objets

Page 50: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Puzzler #2 - QCM

1. Il pousse un juron2. Il ne fait pas ce qu’on pense3. Il bench Hotspot4. Il crée environ 10.000 objets

Page 51: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Puzzler #2 - solution

• Après ~10.000 itérations, le code est supprimé

Page 52: How to fail at benchmarking?

@YourTwitterHandle@YourTwitterHandle@pingtimeout#FailAtBenchs

Coordinated Omission

Page 53: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Java 8 Enterprisy REST API

Page 54: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

CO client

Page 55: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Runner

• Simuler de lonnnngues pause (11 secondes)

• GC

• autre tâche bloquante

• Technique: ^Z

Page 56: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Récapitulatif - Timeline

Page 57: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Récapitulatif avant run

• Fréquence = 1 req/s

• Durée totale = 100s

• Longue pause = 11s

• Temps de réponse nominal ≈ 10ms

Page 58: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Attentes - Débit

Page 59: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Attentes - Latence

Page 60: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Attentes - centiles

• Calcul anticipé des centiles (en secondes)

• Max ∈ ]10; 11]

• 99% ∈ ]9; 10]

• 98% ∈ ]8; 9]

• 95% ∈ ]5; 6]

• 90% ∈ ]0; 1]

Page 61: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Réalité

Wait… What?

Page 62: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Réalité

Page 63: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Pourquoi ?

Page 64: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Réalité - Débit

100s

100ème requête

Page 65: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Réalité - Latence

100s

100ème requête

Page 66: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

CO - Définition

• Interval entre les points = i

• Latence nominale << i

• Valeurs extrêmes > x

• Requêtes suivantes retardées

• Après la période néfaste

Page 67: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Qu’est-ce qui est mesuré ?

• 99% des bonnes requêtes

• ≠ 99% de toutes les requêtes

Page 68: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Une erreur fréquenteI rarely see load testers that don't suffer from it, including common testers used in the industry (JMeter, Grinder, HP LoadRunner), benchmarks (YCSB, SPECeverything, etc.), and custom build testers I see used by many low latency shops. » — Gil Tene

Page 69: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Tester le test

• Tester le testeur

• Remplacer le SUT par un noop

• Temps de réponse: 0

• Test ^Z

• Vérifier les hypothèses

Page 70: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Correction

• Connaître le temps d’envoi de chaque requête

• Utiliser ce temps comme temps de départ

• Effet:

• Faire apparaître les requêtes retardées

Page 71: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

• Connaître l’interval entre les envois

• Utiliser HdrHistogram

• Classe Histogram

• copyCorrectedForCoordinatedOmission(…)

• recordValueWithExpectedInterval(…)

Page 72: How to fail at benchmarking?

@YourTwitterHandle@YourTwitterHandle@pingtimeout#FailAtBenchs

Récap

Page 73: How to fail at benchmarking?

@pingtimeout#FailAtBenchs

The successful man will profit from his mistakes and try again in a different way

- Dale Carnegie

Page 74: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Des résultats contextuels

Page 75: How to fail at benchmarking?

http://tiny.cc/FailAtBenchs @pingtimeout#FailAtBenchs

Sources

• https://groups.google.com/d/msg/mechanical-sympathy/

• http://latencytipoftheday.blogspot.fr/

• http://www.websiteoptimization.com/speed/tweak/average-number-web-objects/

• http://tylervigen.com/

• Hotspot source code

Page 76: How to fail at benchmarking?

@YourTwitterHandle@YourTwitterHandle@pingtimeout#FailAtBenchs

Q & A

Page 77: How to fail at benchmarking?

@YourTwitterHandle@YourTwitterHandle@pingtimeout#FailAtBenchs

Merci pour votre attention !