When to implement bluebird library over callbacks

81 Views Asked by At

This is my first time building a full stack react project so any help would be helpful.

Essentially I'm building an endpoint that I would really like to fulfill around 200 request a second. Now looking online that seems like a really reasonable number however since this is my first time doing this I'm not sure if that's true.

Currently using settimeout() I was able to push and resolve 2000ish request or 3000 if you count the preflight request as well in around 3 minutes. This is pretty slow and around 10-20 request per sounds. If I make my request but don't worry resolving the request right away then I can process around 90 request per second. That still isn't what I need in terms of speed and I also would prefer that they are resolved much quicker.

So my current question is would it be better to use the bluebird library because it sounds much faster personally. Also another issue I'm running into when I'm trying to make around 100k+ request is I run out of net resources and I'm not sure how to free up any or how to handle that.

Below is my code

const stepData = async() =>{
    try{
        const body = {record,testtime,current_ma,capacity_mah,specap_mah_g,voltage_v}
        assignToBody(body)

        const response = await fetch('http://localhost:5000/stepdata',{
                method:"POST",
                headers: {"Content-Type": "application/json"},
                body: JSON.stringify(body)
    })}catch(err){
        console.log(err.message)
        setTimeout(delayQue,5000)
        fail = true
        rate = rate + 5
        console.log(rate)
    }
    
}


const delayQue = () =>{

    if(count % 500 == 0 && count > 0 && !fail){
        setTimeout(delayQue,10000)
        assignVals(row)
        row++
        count++
    }
    else if(row < vals.length && !fail){
        setTimeout(delayQue,rate)
        assignVals(row)
        row++
        count++
    }else{
        fail = false
        setTimeout(function(){rate = rate - 5},30000)
    }

}

Functions attached to delayQue() that are called through setTimeOut().

    const assignVals = (row) =>{

    for(let i = 0; i < possibleCols.length;i++){
        if(cols.includes(possibleCols[i])){
            valsToPass[i] = vals[row][cols.lastIndexOf(possibleCols[i])]
        }else{
            valsToPass[i] = null;
        }
    }
    stepData()
}


const assignToBody = (body) =>{
    for(let i = 0; i < possibleCols.length; i++){
        if(cols.includes(possibleCols[i])){
            body[possibleCols[i]] = valsToPass[cols.lastIndexOf(possibleCols[i])]
        } 
    }
}
0

There are 0 best solutions below