Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active June 18, 2020 09:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WebReflection/58729f1935467526167fbae2adcb4ebc to your computer and use it in GitHub Desktop.
Save WebReflection/58729f1935467526167fbae2adcb4ebc to your computer and use it in GitHub Desktop.
Testing various CDN/Static files server on Raspberry Pi and others (ArchLinux here)
#!/usr/bin/env bash
echo ""
echo "benchmarking $(tput bold)$1$(tput sgr0)"
echo ""
case $1 in
nginx )
sudo systemctl start nginx.service ;;
express )
./express.js & ;;
ucdn )
ucdn --source ./jellyfish & ;;
ucdn-forked )
ucdn --source ./jellyfish --forks 128 & ;;
serve )
serve ./jellyfish -p 8080 & ;;
fastify )
./fastify.js & ;;
http-server )
http-server ./jellyfish -s & ;;
esac
PID="$!"
page='http://127.0.0.1:8080/index.html'
while [ "$(curl -I $page 2> /dev/null)" = "" ]; do
sleep 0.1
done
#wrk -t2 -c50 -d10s $page
autocannon -c 50 -t 10 $page
#for i in [1, 2, 3, 4, 5, 6]; do
# ab -n 100 -c 50 $page > bench.txt
# cat bench.txt | grep Request
# sleep 0.1
#done
if [ "$1" = "nginx" ]; then
sudo systemctl stop nginx.service;
else
kill $PID
fi
@WebReflection
Copy link
Author

Jellyfish Demo

https://github.com/WebReflection/archibold.io/tree/gh-pages/demo/

express.js

#!/usr/bin/env node

const {join} = require("path");

const compression = require("compression");
const express = require("express");
const server = express();
server
  .use(compression())
  .use(express.static(join(__dirname, "jellyfish")))
  .listen(8080, () => {
    console.log("http://127.0.0.1:8080/");
  });

fastify.js

#!/usr/bin/env node

const fastify = require('fastify')();
const path = require('path');

fastify.register(require('fastify-static'), {
  root: path.join(__dirname, 'jellyfish')
});

fastify.listen(8080, '0.0.0.0', (err, address) => {
  console.log(address);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment