Mois : juillet 2021

  • MultiThreading en BASH

    MultiThreading en BASH

    Comment faire du MultiThreading en BASH…. En fait c’est assez simple, il suffit des mettre les scripts en arrière-plan et d’attendre qu’ils soient terminés. Bien sûr, il peut exister certaines limitations…. C’est un non-sens de mettre 20 scripts en parallèle quand il n’y a que 4 processeurs….

    Donc pour gérer efficacement le multi-Threading », personnelemen,t je limite le nombre de threads au nombre de processeurs…..

    Voici une manière simple de gérer le multithreading :

    #--------------------------------------------------
    # Get the maximum physical Threads
    function JobMaxPhysicalThreads() {
            echo $(grep -c proc /proc/cpuinfo)
    }
    #--------------------------------------------------
    
    #--------------------------------------------------
    # Is Max Threads count reached ? If yes, wait....
    function JobOngoingThreads() {
        # How many jobs in Background now ?
        echo $(jobs|grep -vi "done"|wc -l)
    }
    #--------------------------------------------------
    
    #--------------------------------------------------
    # Is Max Threads count reached ? If yes, wait....
    function JobMaxThreadsReachedWait() {
        # How many jobs in Background now ?
        JobsInBackGround=$(JobOngoingThreads)
        # Is background processes limit reached ?
        if [[ $JobsInBackGround -gt $nThreadsLimit ]]; then
           # Wait until some slots are available
           while [[ $JobsInBackGround -gt $nThreadsLimit ]]
             do
               sleep 1
               JobsInBackGround=$(JobOngoingThreads)
             done
       fi
    }
    #--------------------------------------------------
    

    Dans le script lui-même avant d’envoyer un nouveau script en arrière-plan, il suffit de vérifier si le nombre de scripts en arrière-plan n’a pas atteint la limite, si oui, alors il suffit d’attendre qu’il y ait un slot de disponible…

    Par exemple :

    ## Check Current Number of Threads...in case, max is reached, wait !
    JobMaxThreadsReachedWait
    ## Launch next Thread
    LaunchNewScript
    

     

  • Comment déterminer le nombre maximum de threads physiques ?

    Comment déterminer le nombre maximum de threads physiques ?

    Lorsque l’on veut faire du multithreading, il faut avant tout savoir le nombre de processeurs disponibles. Plusieurs possibilités pour cela, mais la plus simple :

    echo $(grep -c proc /proc/cpuinfo)
    

     

  • Elasticsearch cluster statuses

    Elasticsearch cluster statuses

    Quick command :

    curl -X GET "localhost:9200/_cat/nodes?v=true&pretty"

     

  • Erreur « max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] » sous docker for Windows

    Erreur « max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] » sous docker for Windows

    Lors du démarrage d’Elasticsearch sous Docker Desktop, vous obtenez ce message d’erreur :

     max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

    Un moyen simple et efficace pour fixer le problème est :

    C:\local\docker\elk>wsl -d docker-desktop
    WIN10LAPTOP:/mnt/host/c/local/docker/elk# sysctl -w vm.max_map_count=262144
    vm.max_map_count = 262144
    WIN10LAPTOP:/mnt/host/c/local/docker/elk# exit
    
    C:\local\docker\elk>

    Ces changements ne sont pas permanent. Après chaque boot, il faut les ré-exécuter. Je cherche un moyen pour les rendre permanent…

    La meilleure option est bien sûr de switcher vers Mac ou Linux. En effet pour ceux-ci, la procédure est bien plus professionelles….