diff --git a/public/css/css.css b/public/css/css.css index 5a2d4f0..1df79ae 100644 --- a/public/css/css.css +++ b/public/css/css.css @@ -18,8 +18,10 @@ h3 { margin: calc(2*var(--margin)) 0 } -h1,h2,h3 { - margin-bottom:0px; +h1, +h2, +h3 { + margin-bottom: 0px; } .header h1 { @@ -130,3 +132,17 @@ body { align-content: center; text-align: center; } + +@media (max-width:600px) { + #content { + grid-template-areas: + "header1" + "content1" + "content2" + "footer1" + "footer2" + "footer3" + ; + grid-template-columns: 1fr; + } +} diff --git a/public/js/md2html.js b/public/js/md2html.js index 2fbd18c..7a20a12 100644 --- a/public/js/md2html.js +++ b/public/js/md2html.js @@ -316,7 +316,7 @@ ${indent}
  • ${header.content} output += "

    Table of Contents

    " + listHTML + "
    "; break; case "title": - output += `

    ${title}

    ` + output += `

    ${title}

    ` break; case "span": output += `${token.content}`; diff --git a/public/posts/Putting hungry minecraft servers to sleep/post.md b/public/posts/Putting hungry minecraft servers to sleep/post.md index 0da0b78..5311ff9 100644 --- a/public/posts/Putting hungry minecraft servers to sleep/post.md +++ b/public/posts/Putting hungry minecraft servers to sleep/post.md @@ -1,7 +1,9 @@ 2 Minecraft Rust Async Networking Proxy CRIU \title + \toc + # Minecraft servers are HUNGRY They hunger for your ram and your cpu. This makes it either expensive or @@ -50,21 +52,65 @@ minecraft protocol instead of HTTP. ## The Minecraft protocol -Minecraft implements its own protocol consistent of packets. My first idea was to see if anybody had created a -rust library for dealing with minecraft packets. +Minecraft implements its own protocol consistent of packets. My first idea +was to see if anybody had created a rust library for dealing with minecraft +packets. -While some did exist, most of them where unfinished or couldn't do what I wanted. [One crate](https://www.youtube.com/watch?v=E4WlUXrJgy4) -was useful for seeing how an implementation of parsing packets was done, but ultimately I had to write my own parser. +While some did exist, most of them where unfinished or couldn't do what I +wanted. [One crate](https://www.youtube.com/watch?v=E4WlUXrJgy4) was useful +for seeing how an implementation of parsing packets was done, but ultimately +I had to write my own parser. -*images of minecraft protocol* +***images of minecraft protocol*** ## Detecting the subdomain -Luckily for me, the Minecraft procotol sends the full address it is trying to connect to during the handshake. This meant that I simply -had to parse the handshake and extract the subdomain from the address, see if it matches any configured server, and then redirect all -traffic to the internal port that server runs on. +Luckily for me, the Minecraft procotol sends the full address it is trying to +connect to during the handshake. This meant that I simply had to parse the +handshake and extract the subdomain from the address, see if it matches any +configured server, and then redirect all traffic to the internal port that +server runs on. -*code explanation* +***code explanation*** + +***show images of hibernation and starting*** + +![A server that is starting](/posts/Putting hungry minecraft servers to sleep/starting.png "A server in the middle of starting") +![A server that is hibernating](/posts/Putting hungry minecraft servers to sleep/hibernating.png "An empty server thats been hibernated") + +I've talked a bunch about this hibernation, but how does it actually work? + +# cat /proc/$(ps aux | grep server.jar) > hibernation.txt + +Finally being able to connect to the server it was time for the next item on the list. + +

    ✨**Hibernation**✨

    + +Now, instead of closing the server and restarting it when a player joined I +wanted to hibernate the server and unhibernate it when someone joined. + +I had a feeling this would be possible as this is basically how hibernation +works for your system; it saves the memory to disk and loads it into memory +again upon boot. + +After a bit of searching I found [CRIU](https://criu.org/Main_Page), a program +capable of suspending another program to disk. + +Not only does it save the memory, it also saves all the file descriptors the +program was using (and fails with a million cryptic error messages if any of the +files where changed during hibernation) + +There was a Rust crate for CRIU, however it was poorly documented and didnt support +all the command line arguments I needed, so I resorted to calling the binary. + +This led to the program halting until the unhibernated server closed again, but +it was fixed with a simple fork. + +The only downside to this approach is that CRIU requires root access in order +to read the memory and file descriptors of another process. +Running your minecraft server as root is probably not the smartest idea... + +My solution was to not care about it and hope for the best :D # Why aren't my chunks loading?