Skip to content

Commit 5f14436

Browse files
committed
initial demo commit
Signed-off-by: Adrian Catangiu <[email protected]>
1 parent 7564f07 commit 5f14436

10 files changed

+270
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
xenial.rootfs.id_rsa

copy-root-fs.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
start="${1:-0}"
2+
upperlim="${2:-1}"
3+
4+
#DRIVE="lambda-root.ext4"
5+
DRIVE="rootfs.ext4"
6+
7+
for ((i=start; i<upperlim; i++)); do
8+
echo $i
9+
cp $DRIVE ${DRIVE}-sb"$i"
10+
done
11+

extract-times.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
DATA_DIR=${1:-.}
4+
5+
pushd $DATA_DIR > /dev/null
6+
7+
COUNT=`ls fc-sb* | sort -V | tail -1 | cut -d '-' -f 2 | cut -f 2 -d 'b'`
8+
9+
for i in `seq 0 $COUNT`
10+
do
11+
setup_time=`grep Bash bashlog-fc-sb${i} | cut -d ' ' -f 4`
12+
curl_time=`grep Curl bashlog-fc-sb${i} | cut -d ' ' -f 3`
13+
boot_time=`grep Guest-boot fc-sb${i}-log | cut -f 2 -d '=' | cut -f 4 -d ' '`
14+
total=$(($setup_time + $curl_time + $boot_time))
15+
echo "$i setup $setup_time curl $curl_time boot $boot_time total $total ms"
16+
done
17+
18+
popd > /dev/null
19+

one-time-setup.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Load kernel module
2+
sudo modprobe kvm_intel
3+
4+
# Configure packet forwarding
5+
sudo sysctl -w net.ipv4.conf.all.forwarding=1
6+
7+
# Avoid "nf_conntrack: table full, dropping packet"
8+
sudo sysctl -w net.ipv4.netfilter.ip_conntrack_max=99999999
9+
10+
# Avoid "neighbour: arp_cache: neighbor table overflow!"
11+
sudo sysctl -w net.ipv4.neigh.default.gc_thresh1=1024
12+
sudo sysctl -w net.ipv4.neigh.default.gc_thresh2=2048
13+
sudo sysctl -w net.ipv4.neigh.default.gc_thresh3=4096

parallel-start-many.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
#Usage
4+
## sudo ./parallel-start-many.sh 0 100 5 # Will start VM#0 to VM#99 5 at a time.
5+
6+
start="${1:-0}"
7+
upperlim="${2:-1}"
8+
parallel="${3:-1}"
9+
10+
echo start timestamp: `date +%s%N | cut -b1-13` ms
11+
echo "end timestamps (ms):"
12+
for ((i=0; i<parallel; i++)); do
13+
s=$((i * upperlim / parallel))
14+
e=$(((i+1) * upperlim / parallel))
15+
./start-many.sh $s $e && date +%s%N | cut -b1-13 &
16+
done
17+

run-multiple-seq.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
COUNT="${1:-1}"
4+
5+
let total=0
6+
7+
for i in `seq 1 $COUNT`
8+
do
9+
LOG="output/fc-sb0-log"
10+
rm -f $LOG
11+
./start-firecracker.sh
12+
until grep Overall $LOG 2>&1 > /dev/null
13+
do
14+
true
15+
done
16+
time=$(grep Overall $LOG | cut -f 2 -d '=' | tr -d ' ')
17+
echo "boot #$i took $time us $(($time/1000)) ms"
18+
let total=$total+$time
19+
killall firecracker
20+
done
21+
22+
echo "Mean average is $(($total / $COUNT)) us"
23+

start-firecracker.sh

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
#!/bin/bash -e
2+
SB_ID="${1:-0}" # Default to sb_id=0
3+
4+
START_TS=`date +%s%N | cut -b1-13`
5+
6+
#RO_DRIVE="$PWD/rootfs.ext4"
7+
RO_DRIVE="$PWD/xenial.rootfs.ext4"
8+
#RW_DRIVE="$PWD/rw-drives/fc${SB_ID}.ext4"
9+
RW_DRIVE="$PWD/fc-rw.ext4"
10+
11+
# TODO: Boot vmlinuz/bzImage when supported, https://sim.amazon.com/issues/P12329852
12+
KERNEL="$PWD/vmlinux"
13+
TAP_DEV="fc-sb${SB_ID}-tap0"
14+
15+
# Enable if using bootchart
16+
INIT="/init"
17+
#R_INIT="init=$INIT"
18+
#BOOTCHART_ARGS="initcall_debug printk.time=y quiet init=/sbin/bootchartd bootchart_init=$INIT"
19+
20+
KERNEL_BOOT_ARGS="panic=1 pci=off reboot=k tsc=reliable quiet 8250.nr_uarts=0 ipv6.disable=1 $R_INIT"
21+
#KERNEL_BOOT_ARGS="console=ttyS0 reboot=k panic=1 pci=off nomodules ipv6.disable=1 $R_INIT"
22+
23+
API_SOCKET="/tmp/firecracker-sb${SB_ID}.sock"
24+
CURL=(curl --silent --show-error --header Content-Type:application/json --unix-socket "${API_SOCKET}" --write-out "HTTP %{http_code}")
25+
26+
curl_put() {
27+
local URL_PATH="$1"
28+
local OUTPUT RC
29+
OUTPUT="$("${CURL[@]}" -X PUT --data @- "http://localhost/${URL_PATH#/}" 2>&1)"
30+
RC="$?"
31+
if [ "$RC" -ne 0 ]; then
32+
echo "Error: curl PUT ${URL_PATH} failed with exit code $RC, output:"
33+
echo "$OUTPUT"
34+
return 1
35+
fi
36+
# Error if output doesn't end with "HTTP 2xx"
37+
if [[ "$OUTPUT" != *HTTP\ 2[0-9][0-9] ]]; then
38+
echo "Error: curl PUT ${URL_PATH} failed with non-2xx HTTP status code, output:"
39+
echo "$OUTPUT"
40+
return 1
41+
fi
42+
}
43+
44+
logfile="$PWD/output/fc-sb${SB_ID}-log"
45+
metricsfile="$PWD/output/fc-sb${SB_ID}-metrics"
46+
#metricsfile="/dev/null"
47+
48+
touch $logfile
49+
touch $metricsfile
50+
51+
52+
# Setup TAP device that uses proxy ARP
53+
MASK_LONG="255.255.255.252"
54+
MASK_SHORT="/30"
55+
FC_IP="$(printf '169.254.%s.%s' $(((4 * SB_ID + 1) / 256)) $(((4 * SB_ID + 1) % 256)))"
56+
TAP_IP="$(printf '169.254.%s.%s' $(((4 * SB_ID + 2) / 256)) $(((4 * SB_ID + 2) % 256)))"
57+
FC_MAC="$(printf '02:FC:00:00:%02X:%02X' $((SB_ID / 256)) $((SB_ID % 256)))"
58+
ip link del "$TAP_DEV" 2> /dev/null || true
59+
ip tuntap add dev "$TAP_DEV" mode tap
60+
sysctl -w net.ipv4.conf.${TAP_DEV}.proxy_arp=1 > /dev/null
61+
sysctl -w net.ipv6.conf.${TAP_DEV}.disable_ipv6=1 > /dev/null
62+
ip addr add "${TAP_IP}${MASK_SHORT}" dev "$TAP_DEV"
63+
ip link set dev "$TAP_DEV" up
64+
65+
KERNEL_BOOT_ARGS="${KERNEL_BOOT_ARGS} ip=${FC_IP}::${TAP_IP}:${MASK_LONG}::eth0:off"
66+
67+
# Start Firecracker API server
68+
rm -f "$API_SOCKET"
69+
70+
INSTANTIATE_TS=`date +%s%N | cut -b1-13`
71+
SETUP_DELTA=$(($INSTANTIATE_TS - $START_TS))
72+
73+
#if (($SETUP_DELTA > 99)) ; then
74+
# if [ ! -e perf.pid ] ; then
75+
# perf record -a -o perf-data/pdata${SB_ID} --call-graph dwarf sleep 5 > /dev/null 2>&1 &
76+
# echo $! > perf.pid
77+
# fi
78+
#else
79+
# if [ -e perf.pid ] ; then
80+
# kill `cat perf.pid` || true
81+
# rm -f perf.pid || true
82+
# fi
83+
#fi
84+
85+
echo "Bash setup overhead $SETUP_DELTA ms"
86+
87+
#screen -dmLS "fc-sb${SB_ID}" \
88+
#/usr/bin/env "$PWD/firecracker" \
89+
# --api-sock "$API_SOCKET"
90+
91+
./firecracker --api-sock "$API_SOCKET" --context '{"id": "fc-'${SB_ID}'", "jailed": false, "seccomp_level": 0, "start_time_us": 0, "start_time_cpu_us": 0}' &
92+
#echo trying $CMD
93+
#$($CMD)
94+
95+
sleep 0.005s
96+
97+
START_TS=`date +%s%N | cut -b1-13`
98+
99+
# Wait for API server to start
100+
while [ ! -e "$API_SOCKET" ]; do
101+
echo "FC $SB_ID still not ready..."
102+
sleep 0.01s
103+
done
104+
105+
curl_put '/logger' <<EOF
106+
{
107+
"log_fifo": "$logfile",
108+
"metrics_fifo": "$metricsfile",
109+
"level": "Warning",
110+
"show_level": false,
111+
"show_log_origin": false
112+
}
113+
EOF
114+
115+
curl_put '/machine-config' <<EOF
116+
{
117+
"vcpu_count": 1,
118+
"mem_size_mib": 128
119+
}
120+
EOF
121+
122+
curl_put '/boot-source' <<EOF
123+
{
124+
"kernel_image_path": "$KERNEL",
125+
"boot_args": "$KERNEL_BOOT_ARGS"
126+
}
127+
EOF
128+
129+
curl_put '/drives/1' <<EOF
130+
{
131+
"drive_id": "1",
132+
"path_on_host": "$RO_DRIVE",
133+
"is_root_device": true,
134+
"is_read_only": true,
135+
"rate_limiter": {
136+
"bandwidth": {
137+
"size": 104857600,
138+
"refill_time": 100
139+
}
140+
}
141+
}
142+
EOF
143+
144+
curl_put '/drives/2' <<EOF
145+
{
146+
"drive_id": "2",
147+
"path_on_host": "$RW_DRIVE",
148+
"is_root_device": false,
149+
"is_read_only": false
150+
}
151+
EOF
152+
153+
curl_put '/network-interfaces/1' <<EOF
154+
{
155+
"iface_id": "1",
156+
"guest_mac": "$FC_MAC",
157+
"host_dev_name": "$TAP_DEV",
158+
"state": "Attached"
159+
}
160+
EOF
161+
162+
curl_put '/actions' <<EOF
163+
{
164+
"action_type": "InstanceStart"
165+
}
166+
EOF
167+
168+
BOOTSTART_TS=`date +%s%N | cut -b1-13`
169+
#let CURL_DELTA=$BOOTSTART_TS - $START_TS
170+
CURL_DELTA=$(($BOOTSTART_TS - $START_TS))
171+
172+
echo "Curl overhead: $CURL_DELTA ms"
173+
174+
#exec screen -r "fc-sb${SB_ID}"

start-many.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
#Usage
4+
## sudo ./start.sh 0 100 # Will start VM#0 to VM#99.
5+
6+
start="${1:-0}"
7+
upperlim="${2:-1}"
8+
9+
mkdir -p output
10+
for ((i=start; i<upperlim; i++)); do
11+
./start-firecracker.sh "$i" > output/bashlog-fc-sb${i}
12+
done

vmlinux

20.3 MB
Binary file not shown.

xenial.rootfs.ext4

30 MB
Binary file not shown.

0 commit comments

Comments
 (0)