├── .github └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── 0.initial-setup.sh ├── 9.cleanup.sh ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── copy-root-fs.sh ├── extract-times.sh ├── gnuplot.script ├── microvm-tiles.py ├── one-time-setup.sh ├── parallel-start-many.sh ├── run-multiple-seq.sh ├── scripts ├── ensure_resources.sh ├── one-time-setup.sh ├── setup-network-taps.sh └── setup-tap-with-id.sh ├── start-firecracker.sh └── start-many.sh /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | *Issue #, if available:* 2 | 3 | *Description of changes:* 4 | 5 | * 6 | * 7 | 8 | By submitting this pull request, I confirm that my contribution is made 9 | under the terms of the Apache 2.0 license. 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | resources/ 3 | -------------------------------------------------------------------------------- /0.initial-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | COUNT="${1:-4000}" # Default to 4000 6 | 7 | RES=scripts 8 | 9 | rm -rf output 10 | mkdir output 11 | USR=${SUDO_USER:-$USER} 12 | 13 | chown -R "$USR" output 14 | 15 | pushd "$RES" > /dev/null 16 | 17 | ./one-time-setup.sh 18 | ./setup-network-taps.sh 0 "$COUNT" 100 19 | 20 | popd > /dev/null 21 | -------------------------------------------------------------------------------- /9.cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | COUNT=$(find /sys/class/net/* | wc -l) 6 | 7 | killall iperf3 8 | killall firecracker 9 | 10 | for ((i=0; i /dev/null & 13 | done 14 | 15 | rm -rf output/* 16 | rm -rf /tmp/firecracker-sb* 17 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 4 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) 5 | or contact opensource-codeofconduct@amazon.com with any additional 6 | questions or comments. 7 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's 4 | a bug report, new feature, correction, or additional 5 | documentation, we greatly value feedback and contributions from our community. 6 | 7 | Please read through this document before submitting any issues or 8 | pull requests to ensure we have all the necessary 9 | information to effectively respond to your bug report or contribution. 10 | 11 | ## Reporting Bugs/Feature Requests 12 | 13 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 14 | 15 | When filing an issue, please check [existing open](https://github.com/firecracker-microvm/firecracker-demo/issues), 16 | or [recently closed](https://github.com/firecracker-microvm/firecracker-demo/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), 17 | issues to make sure somebody else hasn't already 18 | reported the issue. Please try to include as much information as you can. 19 | Details like these are incredibly useful: 20 | 21 | * A reproducible test case or series of steps 22 | * The version of our code being used 23 | * Any modifications you've made relevant to the bug 24 | * Anything unusual about your environment or deployment 25 | 26 | ## Contributing via Pull Requests 27 | 28 | Contributions via pull requests are much appreciated. Before sending us 29 | a pull request, please ensure that: 30 | 31 | 1. You are working against the latest source on the *master* branch. 32 | 1. You check existing open, and recently merged, pull requests to make 33 | sure someone else hasn't addressed the problem already. 34 | 1. You open an issue to discuss any significant work - we would hate for 35 | your time to be wasted. 36 | 37 | To send us a pull request, please: 38 | 39 | 1. Fork the repository. 40 | 1. Modify the source; please focus on the specific change you are contributing. 41 | If you also reformat all the code, it will be hard for us to focus on your change. 42 | 1. Ensure local tests pass. 43 | 1. Commit to your fork using clear commit messages. 44 | 1. Send us a pull request, answering any default questions in the pull request interface. 45 | 1. Pay attention to any automated CI failures reported in the pull request, 46 | and stay involved in the conversation. 47 | 48 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) 49 | and [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 50 | 51 | ## Finding contributions to work on 52 | 53 | Looking at the existing issues is a great way to find something to 54 | contribute on. As our projects, by default, use the default GitHub issue 55 | labels ((enhancement/bug/duplicate/help wanted/invalid/question/wontfix), 56 | looking at any ['help wanted'](https://github.com/firecracker-microvm/firecracker-demo/labels/help%20wanted) 57 | issues is a great place to start. 58 | 59 | ## Code of Conduct 60 | 61 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 62 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) 63 | or contact opensource-codeofconduct@amazon.com with any additional questions or comments. 64 | 65 | ## Security issue notifications 66 | 67 | If you discover a potential security issue in this project we ask that you 68 | notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). 69 | Please do **not** create a public github issue. 70 | 71 | ## Licensing 72 | 73 | See the [LICENSE](https://github.com/firecracker-microvm/firecracker-demo/blob/master/LICENSE) 74 | file for our project's licensing. We will ask you to confirm the licensing of 75 | your contribution. 76 | 77 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) 78 | for larger changes. 79 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Firecracker-demo 2 | 3 | ## Disclaimer 4 | 5 | This demo showcases Firecracker's agility and high-density capabiliies. 6 | **It's been run on an EC2 i3.metal host (the defaults start 4000 microVMs) 7 | with an Ubuntu and an Amazon Linux 2 host OS, from an Ubuntu client.** 8 | 9 | Deviations from this setup will probably lead to issues and/or sub-par performance. 10 | If you want to help us support the demo on more platforms...we take 11 | pull requests :) 12 | 13 | ## Step-by-Step Instructions 14 | 15 | Get this repo on an EC2 Intel metal instance. 16 | Open two terminals/ssh-connections to the instance. 17 | 18 | ### Terminal window 1 19 | 20 | will show a heatmap of network traffic done by each microVM. 21 | 22 | ```bash 23 | python3 microvm-tiles.py 24 | ``` 25 | 26 | ### Terminal window 2 27 | 28 | will control the rest of the demo. 29 | 30 | Raise the maximum processes limit. 31 | 32 | ```bash 33 | sudo tee -a /etc/security/limits.conf < ec2-user@:firecracker-demo/{data.log,gnuplot.script} . 141 | gnuplot gnuplot.script 142 | xdg-open boot-time.png # on Ubuntu. For other distros just use your default .png viewer. 143 | ``` 144 | -------------------------------------------------------------------------------- /copy-root-fs.sh: -------------------------------------------------------------------------------- 1 | start="${1:-0}" 2 | upperlim="${2:-1}" 3 | 4 | #DRIVE="lambda-root.ext4" 5 | DRIVE="rootfs.ext4" 6 | 7 | for ((i=start; i /dev/null 11 | 12 | COUNT=$(find . -type f -name "fc-sb*" | sort -V | tail -1 | cut -d '-' -f 2 | cut -f 2 -d 'b') 13 | 14 | for i in $(seq 0 "$COUNT") 15 | do 16 | boot_time=$(grep Guest-boot fc-sb"${i}"-log | cut -f 2 -d '=' | cut -f 4 -d ' ') 17 | echo "$i boot $boot_time ms" >> "$DEST" 18 | done 19 | 20 | popd > /dev/null 21 | 22 | -------------------------------------------------------------------------------- /gnuplot.script: -------------------------------------------------------------------------------- 1 | set term png size 1920,1080 2 | set output "boot-time.png" 3 | 4 | set key left bottom 5 | 6 | stats "data.log" u 1:3 nooutput 7 | 8 | set xrange [0:STATS_max_x] 9 | set yrange [0:STATS_max_y+50] 10 | 11 | set label 1 gprintf("Maximum = %g ms", STATS_max_y) at STATS_pos_max_y-30, STATS_max_y+18 12 | set arrow from STATS_pos_max_y, STATS_max_y+15 to STATS_pos_max_y, STATS_max_y lc rgb 'black' 13 | 14 | set label 2 gprintf("Minimum = %g ms", STATS_min_y) at STATS_pos_min_y-25, STATS_min_y-80 15 | set arrow from STATS_pos_min_y, STATS_min_y-77 to STATS_pos_min_y, STATS_min_y lc rgb 'black' 16 | 17 | f(x) = mean_y 18 | fit f(x) 'data.log' u 1:3 via mean_y 19 | 20 | stddev_y = sqrt(FIT_WSSR / (FIT_NDF + 1)) 21 | 22 | set label 3 gprintf("'Total' mean avg = %g ms", mean_y) at STATS_max_x/2-50, 100 23 | set label 4 gprintf("Standard deviation = %g", stddev_y) at STATS_max_x/2-50, 80 24 | 25 | plot mean_y-stddev_y with filledcurves y1=mean_y lt 1 lc rgb "#b3ffb3" notitle, \ 26 | mean_y+stddev_y with filledcurves y1=mean_y lt 1 lc rgb "#b3ffb3" title "Standard deviation", \ 27 | mean_y w l lt 1 lc rgb "#ffff66" lw 3 title "Mean average", \ 28 | "data.log" u 1:3 title 'Guest Boot' w p lc rgb 'orange' pt 14 ps 1, \ 29 | STATS_min_y w l lc rgb 'blue' notitle, \ 30 | STATS_max_y w l lc rgb 'blue' notitle 31 | 32 | -------------------------------------------------------------------------------- /microvm-tiles.py: -------------------------------------------------------------------------------- 1 | """ 2 | A demo script for visualising on-host microVM network activity. 3 | 4 | Will read bytes recieved by the host on microVM tun/tap devices, as per 5 | `/proc/net/dev` file, and then use that data to color a cell on the terminal. 6 | 7 | The terminal screen is refreshed periodically. The brigher a cell is colored, 8 | the more bytes the host recieved from that microVM. The brightness range is 9 | scaled based on the maximum amount of bytes a microvm has sent in that refresh 10 | cycle. 11 | """ 12 | 13 | #!/usr/bin/python3 14 | 15 | 16 | import curses 17 | import re 18 | import time 19 | 20 | MAX_MICROVMS = 4096 21 | COLOR_BLACK = 101 22 | MICROVM_TAP_REGEX = r'fc-(\d+)-tap' 23 | 24 | 25 | def render_microvms(stdscr): 26 | # Put key-grabbing in no-wait mode. 27 | stdscr.nodelay(True) 28 | 29 | # Clear screen 30 | stdscr.clear() 31 | 32 | # Create a gradient "color palette" with 100 color pairs, from dark grey to 33 | # Amazon orange. Color pair 0 is reserved in curses, we'll start from 1. 34 | for shade in range (1, 101): 35 | curses.init_color(shade, 200 + shade * 8, 200 + int(shade * 4.8), 208) 36 | curses.init_pair(shade, shade, shade) 37 | 38 | # Black for background. 39 | curses.init_color(COLOR_BLACK, 0, 0, 0) 40 | curses.init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK) 41 | 42 | # Seed value for the last iteration's microVM network interface activty. 43 | last_rx = [0] * MAX_MICROVMS 44 | delta_rx = [0] * MAX_MICROVMS 45 | 46 | # Blinky loop of infinite microVM activity rendering 47 | # TODO: End loop on any key press (Ctrl+C required now). 48 | last_iface_idx = 0 49 | while True: 50 | # Reads the latest received bytes on the microVMs' tun/tap interfaces 51 | # and computes the delta against the last iteration, as well as the 52 | # highest delta in this iteration. 53 | with open('/proc/net/dev') as net_iface_list: 54 | # The first two lines of `/proc/net/dev` are headers. 55 | next(net_iface_list) 56 | next(net_iface_list) 57 | 58 | max_rx = 0 59 | for iface_line in net_iface_list: 60 | # Only operate microVM tun/tap lines, and extract their index 61 | # (they show up in an arbitrary order in the file). 62 | scan_for_microvm_tap = re.match(MICROVM_TAP_REGEX, iface_line) 63 | if not scan_for_microvm_tap: 64 | continue 65 | 66 | iface_idx = int(scan_for_microvm_tap.group(1)) 67 | 68 | current_rx = int(iface_line.split()[1]) 69 | delta_rx[iface_idx] = current_rx - last_rx[iface_idx] 70 | last_rx[iface_idx] = current_rx 71 | 72 | if delta_rx[iface_idx] > max_rx: 73 | max_rx = delta_rx[iface_idx] 74 | 75 | if last_iface_idx < iface_idx: 76 | last_iface_idx = iface_idx 77 | 78 | # "Render" all microVMs. Their brightness is proportional to 79 | # delta_rx_bytes/max_rx_bytes 80 | for i in range(0, curses.LINES - 1): 81 | for j in range(0, curses.COLS): 82 | slot_idx = i * curses.COLS + j 83 | # If there's no microVM there yet, use black 84 | if slot_idx > last_iface_idx: 85 | microvm_color = COLOR_BLACK 86 | else: 87 | # Inactive microvms get a grey color. 88 | microvm_color = 1 89 | if max_rx > 0: 90 | microvm_color += int(99 * delta_rx[slot_idx] / max_rx) 91 | 92 | stdscr.addstr(i, j, ' ', curses.color_pair(microvm_color)) 93 | 94 | stdscr.refresh() 95 | time.sleep(0.25) 96 | 97 | 98 | # Run the curses "rendering" loop in the terminal, and clean up after. 99 | curses.wrapper(render_microvms) 100 | 101 | -------------------------------------------------------------------------------- /one-time-setup.sh: -------------------------------------------------------------------------------- 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 14 | 15 | # Add CAP_NET_ADMIN to firecracker (for TUNSETIFF ioctl) 16 | sudo setcap cap_net_admin=eip firecracker 17 | -------------------------------------------------------------------------------- /parallel-start-many.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | # Usage 6 | ## ./parallel-start-many.sh 0 100 5 # Will start VM#0 to VM#99 5 at a time. 7 | 8 | start="${1:-0}" 9 | upperlim="${2:-1}" 10 | parallel="${3:-1}" 11 | 12 | FAIL=0 13 | 14 | echo "Start @ $(date)". 15 | START_TS=$(date +%s%N | cut -b1-13) 16 | 17 | for ((i=0; i&1 > /dev/null 15 | do 16 | true 17 | done 18 | time=$(grep Overall $LOG | cut -f 2 -d '=' | tr -d ' ') 19 | echo "boot #$i took $time us $(($time/1000)) ms" 20 | let total=$total+$time 21 | killall firecracker 22 | done 23 | 24 | echo "Mean average is $(($total / $COUNT)) us" 25 | 26 | -------------------------------------------------------------------------------- /scripts/ensure_resources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" 6 | TEST_RES="$SCRIPT_DIR/../resources" 7 | S3_BUCKET="spec.ccfc.min" 8 | TARGET="$(uname -m)" 9 | FC_VERSION="v1.1.2" 10 | 11 | ensure_firecracker() { 12 | file_path="$TEST_RES/firecracker" 13 | 14 | # Get the specified firecracker version. 15 | TMP_FOLDER="/tmp/tmprelease" 16 | TMP_ARCHIVE="/tmp/release.tgz" 17 | 18 | wget -q "https://github.com/firecracker-microvm/firecracker/releases/download/$FC_VERSION/firecracker-$FC_VERSION-$TARGET.tgz" -O "$TMP_ARCHIVE" 19 | 20 | mkdir -p "$TMP_FOLDER" 21 | tar -zxf "$TMP_ARCHIVE" -C "$TMP_FOLDER" 22 | 23 | # Get the firecracker binary 24 | cp "$(find "$TMP_FOLDER" -name "firecracker*$TARGET*")" "$file_path" 25 | chmod +x "$file_path" 26 | 27 | echo "Saved firecracker at $file_path" 28 | 29 | # Clean up 30 | rm -rf "$TMP_FOLDER" 31 | rm "$TMP_ARCHIVE" 32 | 33 | } 34 | 35 | ensure_kernel() { 36 | file_path="$TEST_RES/vmlinux" 37 | kv="4.14" 38 | wget -q "https://s3.amazonaws.com/$S3_BUCKET/ci-artifacts/kernels/$TARGET/vmlinux-$kv.bin" -O "$file_path" 39 | echo "Saved kernel at $file_path..." 40 | } 41 | 42 | ensure_rootfs() { 43 | file_path="$TEST_RES/rootfs.ext4" 44 | key_path="$TEST_RES/rootfs.id_rsa" 45 | wget -q "https://s3.amazonaws.com/$S3_BUCKET/img/alpine_demo/fsfiles/xenial.rootfs.ext4" -O "$file_path" 46 | wget -q "https://s3.amazonaws.com/$S3_BUCKET/img/alpine_demo/fsfiles/xenial.rootfs.id_rsa" -O "$key_path" 47 | chmod 400 "$key_path" 48 | echo "Saved rootfs and ssh key at $file_path and $key_path..." 49 | } 50 | 51 | mkdir -p "$TEST_RES" 52 | 53 | # Obtain Firecracker. 54 | ensure_firecracker 55 | ensure_kernel 56 | ensure_rootfs 57 | -------------------------------------------------------------------------------- /scripts/one-time-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | # Load kernel module 6 | sudo modprobe kvm_intel 7 | 8 | # Configure packet forwarding 9 | sudo sysctl -wq net.ipv4.conf.all.forwarding=1 10 | 11 | # Avoid "neighbour: arp_cache: neighbor table overflow!" 12 | sudo sysctl -wq net.ipv4.neigh.default.gc_thresh1=1024 13 | sudo sysctl -wq net.ipv4.neigh.default.gc_thresh2=2048 14 | sudo sysctl -wq net.ipv4.neigh.default.gc_thresh3=4096 15 | 16 | 17 | # Download relevant resources. 18 | ./ensure_resources.sh 19 | -------------------------------------------------------------------------------- /scripts/setup-network-taps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | upperlim="${2:-1}" 6 | parallel="${3:-1}" 7 | 8 | for ((i=0; i /dev/null || true 13 | ip tuntap add dev "$TAP_DEV" mode tap 14 | sysctl -w net.ipv4.conf."$TAP_DEV".proxy_arp=1 > /dev/null 15 | sysctl -w net.ipv6.conf."$TAP_DEV".disable_ipv6=1 > /dev/null 16 | ip addr add "${TAP_IP}${MASK_SHORT}" dev "$TAP_DEV" 17 | ip link set dev "$TAP_DEV" up 18 | 19 | iperf3 -B "$TAP_IP" -s > /dev/null 2>&1 & 20 | 21 | -------------------------------------------------------------------------------- /start-firecracker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | SB_ID="${1:-0}" # Default to sb_id=0 6 | 7 | FC_BINARY="$PWD/resources/firecracker" 8 | RO_DRIVE="$PWD/resources/rootfs.ext4" 9 | KERNEL="$PWD/resources/vmlinux" 10 | TAP_DEV="fc-${SB_ID}-tap0" 11 | 12 | KERNEL_BOOT_ARGS="init=/sbin/boottime_init panic=1 pci=off nomodules reboot=k tsc=reliable quiet i8042.nokbd i8042.noaux 8250.nr_uarts=0 ipv6.disable=1" 13 | #KERNEL_BOOT_ARGS="console=ttyS0 reboot=k panic=1 pci=off nomodules i8042.nokbd i8042.noaux ipv6.disable=1" 14 | 15 | API_SOCKET="/tmp/firecracker-sb${SB_ID}.sock" 16 | CURL=(curl --silent --show-error --header "Content-Type: application/json" --unix-socket "${API_SOCKET}" --write-out "HTTP %{http_code}") 17 | 18 | curl_put() { 19 | local URL_PATH="$1" 20 | local OUTPUT RC 21 | OUTPUT="$("${CURL[@]}" -X PUT --data @- "http://localhost/${URL_PATH#/}" 2>&1)" 22 | RC="$?" 23 | if [ "$RC" -ne 0 ]; then 24 | echo "Error: curl PUT ${URL_PATH} failed with exit code $RC, output:" 25 | echo "$OUTPUT" 26 | return 1 27 | fi 28 | # Error if output doesn't end with "HTTP 2xx" 29 | if [[ "$OUTPUT" != *HTTP\ 2[0-9][0-9] ]]; then 30 | echo "Error: curl PUT ${URL_PATH} failed with non-2xx HTTP status code, output:" 31 | echo "$OUTPUT" 32 | return 1 33 | fi 34 | } 35 | 36 | logfile="$PWD/output/fc-sb${SB_ID}-log" 37 | #metricsfile="$PWD/output/fc-sb${SB_ID}-metrics" 38 | metricsfile="/dev/null" 39 | 40 | touch "$logfile" 41 | 42 | # Setup TAP device that uses proxy ARP 43 | MASK_LONG="255.255.255.252" 44 | #MASK_SHORT="/30" 45 | FC_IP="$(printf '169.254.%s.%s' $(((4 * SB_ID + 1) / 256)) $(((4 * SB_ID + 1) % 256)))" 46 | TAP_IP="$(printf '169.254.%s.%s' $(((4 * SB_ID + 2) / 256)) $(((4 * SB_ID + 2) % 256)))" 47 | FC_MAC="$(printf '02:FC:00:00:%02X:%02X' $((SB_ID / 256)) $((SB_ID % 256)))" 48 | #ip link del "$TAP_DEV" 2> /dev/null || true 49 | #ip tuntap add dev "$TAP_DEV" mode tap 50 | #sysctl -w net.ipv4.conf.${TAP_DEV}.proxy_arp=1 > /dev/null 51 | #sysctl -w net.ipv6.conf.${TAP_DEV}.disable_ipv6=1 > /dev/null 52 | #ip addr add "${TAP_IP}${MASK_SHORT}" dev "$TAP_DEV" 53 | #ip link set dev "$TAP_DEV" up 54 | 55 | KERNEL_BOOT_ARGS="${KERNEL_BOOT_ARGS} ip=${FC_IP}::${TAP_IP}:${MASK_LONG}::eth0:off" 56 | 57 | # Start Firecracker API server 58 | rm -f "$API_SOCKET" 59 | "${FC_BINARY}" --api-sock "$API_SOCKET" --id "${SB_ID}" --boot-timer >> "$logfile" & 60 | 61 | sleep 0.015s 62 | 63 | # Wait for API server to start 64 | while [ ! -e "$API_SOCKET" ]; do 65 | echo "FC $SB_ID still not ready..." 66 | sleep 0.01s 67 | done 68 | 69 | curl_put '/logger' <