# Dec 16th, 2017: \[FR\]\[Elasticsearch\] Tests de performance pour votre plugin Elasticsearch

**URL:** <https://discuss.elastic.co/t/dec-16th-2017-fr-elasticsearch-tests-de-performance-pour-votre-plugin-elasticsearch/109105>\
**Category:** Advent Calendar\
**Created:** [December 16, 2017, 12:00am UTC](https://discuss.elastic.co/t/dec-16th-2017-fr-elasticsearch-tests-de-performance-pour-votre-plugin-elasticsearch/109105 "2017-12-16T00:00:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 16, 2017, 12:00am UTC](https://discuss.elastic.co/t/dec-16th-2017-fr-elasticsearch-tests-de-performance-pour-votre-plugin-elasticsearch/109105/1 "2017-12-16T00:00:09Z")

</div>

# Tests de performance pour votre plugin Elasticsearch

Imaginons que nous ayons développé un nouveau plugin Ingest pour Elasticsearch.  
Se pose la question de l'impact éventuel sur les performances lors de l'insertion de nouveaux documents.

Aujourd'hui, nous allons voir comment utiliser [Rally](https://github.com/elastic/rally) pour comparer les performances d'ingestion entre un pipeline vide et un pipeline utilisant notre plugin.

Quelques suppositions avant de démarrer nos moteurs :

- Rally est déjà [installé](https://github.com/elastic/rally#installing-rally)
- Rally est déjà [configuré](https://github.com/elastic/rally#configure)
- Nous utilisons Elasticsearch 6.0.0
- Le code source de notre projet est dans `~/dev/elasticsearch/ingest-foo`
- Nous utilisons Gradle et le plugin `elasticsearch.esplugin`

La première chose à faire est de déclarer notre plugin dans `~/.rally/rally.ini` dans la section `[source]` :

```ini
[source]
plugin.ingest-foo.src.dir = ~/dev/elasticsearch/ingest-foo/
plugin.ingest-foo.build.task = assemble
plugin.ingest-foo.build.artifact.subdir = build/distributions

```

Il nous reste à créer notre "piste" sur laquelle se dérouleront nos différentes courses dans `~/dev/rally-tracks/ingest-foo` en ajoutant un fichier `track.json` :

```json
{
  "description": "Ingest Foo benchmark",
  "indices": [
    {
      "name": "persons",
      "types": [
        {
          "name": "type",
          "mapping": "mappings.json",
          "documents": "documents.json",
          "document-count": 1000000,
          "uncompressed-bytes": 361027465
        }
      ]
    }
  ],
  "challenges": [
    {% include "challenges/with-ingest-empty.json" %},
    {% include "challenges/with-ingest-foo.json" %}
  ]
}

```

Vous devez fournir le mapping à appliquer ainsi que les documents à insérer dans Elasticsearch en écrivant les fichiers `~/dev/rally-tracks/ingest-foo/mappings.json` et `~/dev/rally-tracks/ingest-foo/documents.json`.

Attention ! Les champs `document-count` et `uncompressed-bytes` doivent être ajustés en conséquence. Le premier étant le nombre de documents, le second étant la taille en octets du fichier.

Créons le fichier `~/dev/rally-tracks/ingest-foo/challenges/with-ingest-empty.json` :

```json
{
   "name":"index-with-ingest-empty",
   "default":false,
   "index-settings":{
      "index.number_of_replicas":0
   },
   "schedule":[
   {
      "name": "define-pipeline-empty",
      "operation": {
         "operation-type" : "put-pipeline", 
         "id": "empty",
         "body": {
            "description": "Do nothing",
            "processors": [
            ]
          }
       }
    },
    {
       "name": "bulk-index",
       "operation": {
          "operation-type" : "bulk",
          "bulk-size": 10000,
          "pipeline": "empty"
       },
       "warmup-time-period":120,
       "clients":8
    }
  ]
}

```

Créons le fichier `~/dev/rally-tracks/ingest-foo/challenges/with-ingest-foo.json` :

```json
{
   "name":"index-with-ingest-foo",
   "default":true,
   "index-settings":{
      "index.number_of_replicas":0
   },
   "schedule":[
   {
      "name": "define-pipeline-foo",
      "operation": {
         "operation-type" : "put-pipeline", 
         "id": "foo",
         "body": {
            "description": "Using foo processor",
            "processors": [
            {
              "foo": {
                 // Settings if any
              }
            }
            ]
          }
       }
    },
    {
       "name": "bulk-index",
       "operation": {
          "operation-type" : "bulk",
          "bulk-size": 10000,
          "pipeline": "foo"
       },
       "warmup-time-period":120,
       "clients":8
    }
  ]
}

```

Nous pouvons maintenant lancer nos courses avec :

```auto
esrally --distribution-version=6.0.0 \
        --elasticsearch-plugins="ingest-foo" \
        --revision="ingest-foo:current" \
        --track-path=~/dev/rally-tracks/ingest-foo \
        --challenge index-with-ingest-empty

```

Rally va automatiquement installer la bonne version d'elasticsearch, compiler et fabriquer notre plugin, l'installer dans elasticsearch puis démarrer la course et mesurer ce qui se passe.

Changeons le challenge pour la deuxième exécution par `index-with-ingest-foo`.  
Et comparons les résultats, en listant d'abord les courses :

```auto
esrally list races

```

```auto
Race Timestamp Track Track Parameters Challenge Car User Tag
---------------- ---------- ------------------ ----------------------- -------- ----------
20171213T112530Z ingest-foo index-with-ingest-empty defaults
20171213T111908Z ingest-foo index-with-ingest-foo defaults

```

Puis en les comparant :

```auto
esrally compare --baseline=20171213T112530Z --contender=20171213T111908Z

```

Ce qui nous donne :

```auto
------------------------------------------------------
    _________  _____                    
   / ____(_)___  _____/ / /___ / _________________ 
  / /_ / / __\/__ `/ / \ __\/___ / __\/___ / _ \
 / __/ / / / / / /_/ / /___ / / / __/ /_/ / / /__ /
/_/ /_/_/ /_/\ __,_/_/ /____ /\ ___/\____ /_/ \___/ 
------------------------------------------------------

| Metric | Task | Baseline | Contender | Diff | Unit |
|------------------------------:|-----------:|-----------:|------------:|---------:|-------:|
| Indexing time | | 3.77223 | 3.93535 | 0.16312 | min |
| Index size | | 0.610304 | 0.609114 | -0.00119 | GB |
| Totally written | | 0.97401 | 1.04273 | 0.06872 | GB |
| Min Throughput | bulk-index | 12663.4 | 12285.3 | -378.048 | docs/s |
| Median Throughput | bulk-index | 14510.2 | 14385.5 | -124.698 | docs/s |
| Max Throughput | bulk-index | 16457.6 | 15673.3 | -784.371 | docs/s |

```

Cela nous permet de voir rapidement que la valeur médiane du ralentissement causé par notre plugin est de 125 documents par seconde soit un peu moins de 9%.

Bonne route et soyez prudents !

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 23, 2018, 8:31am UTC](https://discuss.elastic.co/t/dec-16th-2017-fr-elasticsearch-tests-de-performance-pour-votre-plugin-elasticsearch/109105/2 "2018-08-23T08:31:18Z")

</div>


