-3

I want to make a booking on a site that opens for booking only half an hour a week. During this time an enormous number of people rush to make booking. When the site gets highly crowded it is impossible for me to normally do my booking. thus, I must do a JS Fitch. However, neither doing fetch one time, nor doing fetch within a loop is enough. that's already what I have made. otherwise, I should run fetches in parallel so that a request should be made let's say a hundred times parallelly.

My question how to do for example 100 fetch, parallelly, each request.

  var registerUrl = "/API/booking.php";
  const params = {
    val1: document.querySelector('#val1').value.trim(),
    val2: document.querySelector('#val2').value.trim(),
    val3: document.querySelector('#val3').value.trim(),
    val4: document.querySelector('#val4').value.trim(),
    val5: document.querySelector('#val5').value.trim(),
    val6: document.querySelector('#val6').value.trim()
  };

const registerRequest = async (url) => {
    const response = await fetch( url ,
      {
          method: 'POST',
          body: new URLSearchParams(params)
      })
      .then((response) => {
              response.text().then((data) => {
                if(data.trim() == "success")
                {
                  console.log("donesuccessfully")
                }
              }
          });
      })
};


// here I need to do 100 request each loop
for (let i = 0; i < 1000; i++) {
    // each loop round I need to do registerRequest(registerUrl) * 100
    registerRequest(registerUrl); 
}
// the whole amount will be 1000 in loop and 100 parallels each loop
Bergi
  • 572,313
  • 128
  • 898
  • 1,281
devoloper
  • 33
  • 6

0 Answers0