0.0.1-security.1 • Published 1 year ago

@swenkerorg/nulla-voluptates-voluptates v0.0.1-security.1

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

@swenkerorg/nulla-voluptates-voluptates

A simple lib to manage multiple processes on nodejs. It makes horizontal scaling easy on multiple machines over HTTP traffic.

Installation

npm install @swenkerorg/nulla-voluptates-voluptates

Usage

import slavery from 'slaveryr-js';

//Make different timeouts
let make_timeout = s =>
    new Promise( resolve => {
        setTimeout( () => {
            resolve(s)
        }, s * 1000)
    })

let timeouts = [ 1, 2, 3, 4, 5, 6, 7, 8 ].reverse()

// options to pass to the engine    
let options = {
    numberOfSlaves: 9, // number of processes to run concurrently, this includes the master process
    // if this is not set, it will create a process relative to the number of cores in the machine
    port: 3003, // port to be used to communicate between slave and master
    host: 'localhost', // network host
}

//Create the engine
    slavery(options)
        .master( async master => { // initialize the master
            /* This is the functions that will run in the master */
            // wait until at least one salve is connected
            await master.untilConnected();  
            // random array of big numbers
            // for every number in the array
            for (let timeout of timeouts ){
                // Get a slave that is not currently working
                let slave = await master.getIdle(); 
                slave.run(timeout)
                    .then( result => // result returned by slave
                        console.log( result )
                    );
            }
        }).slave( async (parameter, slave) => { // create the salve 
            /* 
             * it takes a function which is to be run then master runs: 'slave.run(params)
             * the params passed to slave.run(params) is the first parameter of this function, in this case, 'counter'.
             * The second is the slave object. 
             * */
            let timeout = make_timeout(parameter);
            let s = await timeout;
            // run some code
            if( s > 7 )
                return { result: `waited for ${s} seconds, 😡` }
            else if( s > 5 )
                return { result: `waited for ${s} seconds, 😐` }
            else if( s > 2  )
                return { result: `waited for ${s} seconds, 😃` }
            else
                return { result: `waited for ${s} seconds, 😄` }
        })
});

Multiple functions

import slavery from '@swenkerorg/nulla-voluptates-voluptates';

slavery({
    numberOfSlaves: 3, // number of processes to run concurrently, this includes the master process
    // if this is not set, it will create process relative the the number of cores in the machine
    port: 3003, // port to be used to communicate between salve and master
    host: 'localhost', // network host
}).master( async master => { // initialize the master
    while( true ) {
        // get idle slave
        let slave = await master.getIdle(); 
        //  check if the salve has done the setup
        let isReady = await slave.is_done('setup');
        // if it has not done the initial setup, run the setup function
        if( !isReady ) 
            slave.run(setup_paramters, 'setup')
        else // if it has done the initial setup, run the default function
            result = slave.run(defualt_parameters)
    }
}).slave( {
    'setup': async (name, slave) => {
        /* let add run the first function with the tag 'setup'
         * this will be the first function to run which will do the initial set up
         * in this case create an instance of the class TestClassic with a given name
         * for the default funtion to the run
         * */
        // create intial setup
        let setup = new Setup();
        // save the setup in the slave
        slave.set('setup', setup);
    }, 
    'default': async (params_for_testClassic, salve) => {
        let setup = salve.get('setup');
        let result = setup.run();
        return result;
    }, 
    'clean up': async (param, slave) => {
        slave.set('setup', null);
        setup.clean();
    }
})

Options

import { Server } from "socket.io";

slavery({
    numberOfSlaves: 3, // number of processes to run concurrently, this includes the master process
    port: 3003, // port to be used to communicate between salve and master
    host: 'localhost', // network host
    timeout: 1000, // time to wait for a slave to respond, default is null
    crashOnError: false, // the defaul is to try to keep the slave alive as mush as possible, this will let the process crash on error
    passErrorToMaster: true, // the default is to pass the error to the master, so that the master can handle the error, 
                             // if this is set to false, it is up to the slave to handle the error
    maxTransferSize: 1e9, // the maximum size of data that can be passed between the master and the slave, default is 1e9 = 1GB
    io:  new Server(), // this is the io server socket to be used in the master and slave, if this is not set, it will create a new io client socket
    heartBeat: 1000, // this is the set interval time to check on the slaves, 
    // if this is too high the master process will only be able to checking on the slave an won't have time to run the callback, 
    // if this is too low the master won't have time to check on the slave, 
    // the default is set dynamically based on the number of slaves.
}).master(() => {})
.slave(() => {})
    ```
@zitterorg/vel-at-tenetur@hishprorg/ipsa-consectetur-minima@hishprorg/nemo-blanditiis@hishprorg/quis-quibusdam@hishprorg/quis-doloribus@hishprorg/quidem-et@hishprorg/quis-est@hishprorg/sed-nihil-iusto@hishprorg/sequi-inventore-labore@hishprorg/sed-sunt@hishprorg/tempore-dolor-ut@zitterorg/amet-porro-impedit@zitterorg/amet-minus@zitterorg/amet-vero-laboriosam@zitterorg/amet-accusamus@zitterorg/animi-accusantium-similique@zitterorg/animi-atque@zitterorg/aliquid-ducimus-provident@zitterorg/asperiores-consectetur@zitterorg/aspernatur-pariatur-occaecati@zitterorg/architecto-dolore@zitterorg/asperiores-molestias@zitterorg/aut-fugit@zitterorg/earum-harum@zitterorg/doloribus-itaque@zitterorg/doloribus-quidem-enim@zitterorg/hic-suscipit@zitterorg/harum-ratione@zitterorg/hic-dicta@zitterorg/illum-perferendis-consectetur@zitterorg/nemo-dolorem@zitterorg/necessitatibus-doloremque@zitterorg/natus-tempora@zitterorg/nemo-tenetur@zitterorg/numquam-itaque@zitterorg/pariatur-ad@zitterorg/perferendis-id@zitterorg/quaerat-error-quae@zitterorg/quasi-corrupti-voluptates@zitterorg/quas-in-suscipit@zitterorg/qui-dicta@zitterorg/quas-autem@zitterorg/quisquam-distinctio-veritatis@zitterorg/quis-maxime@zitterorg/quod-veritatis@zitterorg/ab-fugiat-impedit@zitterorg/a-in@zitterorg/at-esse-odit@zitterorg/consequatur-eius@zitterorg/blanditiis-esse-iusto@zitterorg/corporis-sit@zitterorg/cupiditate-fugiat-culpa@zitterorg/corrupti-animi-beatae@zitterorg/corporis-ut-consectetur@zitterorg/cum-commodi@zitterorg/cum-non@zitterorg/dolor-laboriosam@zitterorg/dolor-nostrum-porro@zitterorg/dolore-quas@zitterorg/distinctio-perferendis@zitterorg/eum-expedita@zitterorg/fugit-ex-neque@zitterorg/impedit-ex-praesentium@zitterorg/inventore-facere@zitterorg/incidunt-voluptas@zitterorg/ipsum-magnam@zitterorg/itaque-nisi-veritatis@zitterorg/itaque-nesciunt-voluptatibus@zitterorg/itaque-sapiente-similique@zitterorg/itaque-ab@zitterorg/occaecati-beatae@zitterorg/quibusdam-sit-qui@zitterorg/quia-sapiente@zitterorg/quibusdam-numquam@zitterorg/rem-iure@zitterorg/repellat-ut@zitterorg/repudiandae-blanditiis@zitterorg/reprehenderit-soluta-ad@zitterorg/repellendus-impedit-repellendus@zitterorg/repudiandae-nihil-architecto@zitterorg/saepe-eos@zitterorg/sint-veritatis@zitterorg/tempore-debitis-minima@zitterorg/sit-expedita@zitterorg/totam-quos-dolorem@zitterorg/unde-exercitationem@zitterorg/velit-dicta@zitterorg/veritatis-repellat-debitis@zitterorg/voluptate-voluptatem@zitterorg/adipisci-quae-eius@zitterorg/accusantium-reprehenderit-quisquam@zitterorg/accusantium-quam@zitterorg/adipisci-ipsum@zitterorg/adipisci-autem@zitterorg/accusamus-quos-consequuntur@zitterorg/aperiam-nisi@zitterorg/consequuntur-perspiciatis@zitterorg/corporis-architecto@zitterorg/consequuntur-illum-corrupti@zitterorg/delectus-est
0.0.1-security

1 year ago

1.4.39

1 year ago

1.4.38

1 year ago

1.4.40

1 year ago

1.4.42

1 year ago

1.4.41

1 year ago

1.4.44

1 year ago

1.4.43

1 year ago

1.5.58

1 year ago

1.4.46

1 year ago

1.5.57

1 year ago

1.4.45

1 year ago

1.4.48

1 year ago

1.4.47

1 year ago

1.4.49

1 year ago

1.4.51

1 year ago

1.4.50

1 year ago

1.4.53

1 year ago

1.4.52

1 year ago

1.4.55

1 year ago

1.4.54

1 year ago

1.4.57

1 year ago

1.4.56

1 year ago

1.2.19

1 year ago

1.3.32

1 year ago

1.2.20

1 year ago

1.2.23

1 year ago

1.2.24

1 year ago

1.2.21

1 year ago

1.2.22

1 year ago

1.2.27

1 year ago

1.2.28

1 year ago

1.2.25

1 year ago

1.2.26

1 year ago

1.2.29

1 year ago

1.2.30

1 year ago

1.2.31

1 year ago

1.4.33

1 year ago

1.4.32

1 year ago

1.4.35

1 year ago

1.4.34

1 year ago

1.4.37

1 year ago

1.2.32

1 year ago

1.4.36

1 year ago

1.2.18

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago