https://justine.lol/redbean/index.html
[redbean]
redbean
single-file distributable web server
redbean makes it possible to share web applications that run offline
as a single-file actually pdrtable executable zip archive which
contains your assets. All you need to do is download the redbean.com
program below, change the filename to .zip, add your content in a zip
tool like Windows 10 or InfoZIP, and change the extension back to
.com.
redbean can serve 1 million+ gzip encoded responses per second on a
cheap personal computer. That performance is thanks to zip and gzip
using the same compression format, which enables kernelspace copies.
Another reason redbean goes fast is that it's a tiny static binary,
which makes fork memory paging nearly free.
redbean is also easy to modify to suit your own needs. The program
itself is written as a single .c file.
download # [win] # # [ope] #
redbean-2021-02-25.com
200kb - PE+ELF+MachO+ZIP+SH
redbean-2021-02-25.com.dbg
2.2m - ELF debugger data (optional)
redbean.c
source code
features
* HTTP v1.1
* Content-Encoding
* Range / Content-Range
* Last-Modified / If-Modified-Since
installation
curl https://justine.lol/redbean/redbean-latest.com >redbean.com
chmod +x redbean.com
bash -c './redbean.com -vv'
usage
echo '<b>hello' >index.html
zip redbean.com index.html
./redbean.com -vv
curl -v http://127.0.0.1:8080/index.html
details
Assets can be listed by running the following command:
unzip -vl redbean.com # lists files
Assets can be added to the zip archive as follows:
zip redbean.com index.html # adds file
By default, anything you add to the archive gets compressed.
Sometimes you don't want that to happen. A good example is video
files. The web browser will want to send HTTP range requests to seek
in the video, in which case redbean requires that the asset be
uncompressed.
zip -0 redbean.com video.mp4 # adds file without compression
Each connection uses a point in time snapshot of your ZIP file. If
your ZIP is deleted then serving continues. If it's replaced then
issuing SIGUSR1 (or SIGHUP if daemon) will reindex the zip for
subsequent connections without interrupting active ones. If SIGINT or
SIGTERM is issued then a graceful shutdown is started but if it's
issued a second time, active connections are reset.
flags
-h help
-v verbosity
-d daemonize
-s uniprocess
-m log messages
-c INT cache seconds
-r /X=/Y redirect X to Y
-l ADDR listen ip [default 0.0.0.0]
-p PORT listen port [default 8080]
-L PATH log file location
-P PATH pid file location
-U INT daemon set user id
-G INT daemon set group id
-B STR changes server header
benchmark
$ wrk -H 'Accept-Encoding: gzip' -t 12 -c 120 \
http://127.0.0.1:8080/tool/net/redbean.html
Running 10s test @ http://127.0.0.1:8080/tool/net/redbean.html
12 threads and 120 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 745.49us 8.79ms 406.77ms 99.54%
Req/Sec 96.60k 6.10k 123.66k 77.36%
11631210 requests in 10.10s, 7.96GB read
Requests/sec: 1151621.71
Transfer/sec: 807.23MB
see also
justine's web page
actually pdrtable executable
twitter.com/justinetunney
github.com/jart
Written by Justine Tunney
jtunney@gmail.com