172 lines
No EOL
6.8 KiB
HTML
172 lines
No EOL
6.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Jose's Parallel Node Service</title>
|
|
<script src="/modal.js"></script>
|
|
<link rel="stylesheet" href="/main-light.css">
|
|
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
}
|
|
|
|
.flex-container {
|
|
display: flex;
|
|
flex-direction: column;
|
|
width: 100vw;
|
|
height: 100vh;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
form {
|
|
max-width: 1024px;
|
|
margin: auto;
|
|
}
|
|
|
|
.info {
|
|
position: absolute;
|
|
top: 0.5em;
|
|
left: 0.5em;
|
|
font-size: 2em;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
|
|
<script>
|
|
const updateWithData = (jsonData) => {
|
|
let results = document.getElementById("results");
|
|
|
|
results.style.display = "none";
|
|
|
|
document.getElementById("serial-time").innerText = jsonData.serial.time[1];
|
|
document.getElementById("parallel-time").innerText = jsonData.parallel.time[1];
|
|
results.style.display = "block";
|
|
};
|
|
|
|
window.addEventListener("DOMContentLoaded", (evt) => {
|
|
// Form Validation
|
|
let input = document.querySelector("input[type=number]");
|
|
input.addEventListener('change', () => {
|
|
let numPrimes = parseInt(input.value);
|
|
if (numPrimes < 1) {
|
|
document.forms[0].primes.value = 1;
|
|
}
|
|
if (numPrimes > 10) {
|
|
document.forms[0].primes.value = 10;
|
|
}
|
|
});
|
|
|
|
let submitBtn = document.getElementById("submitBtn");
|
|
submitBtn.addEventListener('click', (evt) => {
|
|
try {
|
|
let numPrimes = parseInt(document.forms[0].primes.value);
|
|
|
|
if (numPrimes < 1) {
|
|
numPrimes = 1;
|
|
document.forms[0].primes.value = 1;
|
|
}
|
|
if (numPrimes > 10) {
|
|
numPrimes = 10;
|
|
document.forms[0].primes.value = 10;
|
|
}
|
|
submitBtn.setAttribute("disabled", "");
|
|
fetch(`/primes?num=${numPrimes}`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" }
|
|
}).then(output => {
|
|
if (output.status === 200) {
|
|
output.json().then((data) => {
|
|
updateWithData(data);
|
|
submitBtn.removeAttribute("disabled");
|
|
})
|
|
}
|
|
});
|
|
} catch (err) {
|
|
console.log(err);
|
|
alert("Invalid Number of Primes Given")
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="info" for-modal="info">
|
|
<i class="fa fa-info-circle"></i>
|
|
</div>
|
|
<div class="flex-container">
|
|
<div class="centered container">
|
|
<h2>
|
|
Multi-Threaded NodeJS Server Test
|
|
</h2>
|
|
<form action="/primes" method="POST" onkeydown="return event.key != 'Enter';">
|
|
<div class="labelled flex-form">
|
|
<label for="primes">How Many Primes to Create:</label>
|
|
<input name="primes" type="number" value="5" min="1" , max="10">
|
|
</div>
|
|
</form>
|
|
<p>
|
|
(The max is 10 due to server hardware constraints)
|
|
</p>
|
|
<button id="submitBtn">Submit</button>
|
|
|
|
</div>
|
|
<div class="centered container" id="results" style="display: none;">
|
|
<h2>Results</h2>
|
|
<p>
|
|
Serial Time: <span id="serial-time"></span>ns.
|
|
</p>
|
|
<p>
|
|
Parallel Time: <span id="parallel-time"></span>ns.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="info" class="modal">
|
|
<div class="modal-content" style="max-width: 1024px;">
|
|
<span class="close">
|
|
<i class="fa fa-times"></i>
|
|
</span>
|
|
<h3 class="header">
|
|
About this Website
|
|
</h3>
|
|
<div>
|
|
<p>
|
|
This website was built using NodeJS and the library <span class="code">webworker-threads</span> for
|
|
NodeJS. This library allows me to spin off additional threads as threads, "workers" or in a
|
|
threadpool. This site utilizes the threadpool feature to generate a list of primes (based on your
|
|
selection). Upon hitting "Submit" the button will be disabled, the data will be sent to my server
|
|
and the primes will be generated in serial and in parallel with the specified number of threads.
|
|
</p>
|
|
<p>
|
|
Once it's done processing, a portion will show up in the bottom showing the serial and paralell
|
|
run-times. Obviously I'd like to show the resulting array, but after about 9 hours of work I could
|
|
not get the array returned back out of the threadpool. I could access the array within the
|
|
threadpool but not outside of it (which is where the rest of this server is running..), but overall
|
|
this was not easy to implement in the first place so I'm thrilled it works.
|
|
</p>
|
|
<p>
|
|
My greatest takeaway is that this couldn't have been easy to implement for the developers of the
|
|
NodeJS
|
|
parallel libraries discussed <a href="https://ieeexplore.ieee.org/abstract/document/8671573"
|
|
target="_blank">in this paper</a>, based on the clear limitations and difficulties in
|
|
implementation. Clearly NodeJS itself needs a massive redesign as it lacks many of the creature
|
|
comforts that make parallelism intuitive to use.
|
|
</p>
|
|
<div class="divider"> </div>
|
|
<p>
|
|
One random thing: this website is using a themekit I designed. If you like it and want to use it,
|
|
please do! You can see a real demo <a href="https://oitsjustjose.com/JuiceUI"
|
|
target="_blank">here</a> and you can grab it and use it <a
|
|
href="https://github.com/oitsjustjose/JuiceUI" target="_blank">here</a>!
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
|
|
</html> |