<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Paul Bauer on Medium]]></title>
        <description><![CDATA[Stories by Paul Bauer on Medium]]></description>
        <link>https://medium.com/@pmbauer?source=rss-27e0dd974ad9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6K9fifxEg0uFmzpK.jpeg</url>
            <title>Stories by Paul Bauer on Medium</title>
            <link>https://medium.com/@pmbauer?source=rss-27e0dd974ad9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 09:39:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pmbauer/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[an HAProxy, segfaulted, choose-your-own stack frame adventure]]></title>
            <link>https://engineering.udacity.com/haproxy-segfault-adventure-18cc1a7e1171?source=rss-27e0dd974ad9------2</link>
            <guid isPermaLink="false">https://medium.com/p/18cc1a7e1171</guid>
            <category><![CDATA[postmortem]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[udacity]]></category>
            <category><![CDATA[high-availability]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Paul Bauer]]></dc:creator>
            <pubDate>Tue, 19 Jul 2016 15:33:00 GMT</pubDate>
            <atom:updated>2016-07-19T19:54:52.106Z</atom:updated>
            <content:encoded><![CDATA[<p>Reverse proxy routers mysteriously segfault. Docker ignores your cries for a core dump. Stack Overflow quietly smirks at your solitary misfortune. You can retreat to defetal position and give up on your microservices dream, or you can pick up your gdb, face down Docker, and go to war.</p><blockquote>Production is war, and war is hell. — <a href="https://youtu.be/sYQ8j02wbCY?t=4m27s">Bryan Cantrill, Dockercon 2015</a></blockquote><h4>backstory</h4><figure><a href="http://www.righto.com/2015/03/12-minute-mandelbrot-fractals-on-50.html"><img alt="" src="https://cdn-images-1.medium.com/max/394/1*1no3r0vKqoB0MSE_eg4Oag.jpeg" /></a><figcaption>IBM 1401 core memory</figcaption></figure><p>In early May your team visited the <a href="http://www.computerhistory.org/">Computer History Museum</a> and enjoyed a lovely demonstration of a <a href="http://www.righto.com/2015/10/repairing-50-year-old-mainframe-inside.html">restored IBM 1401</a>.</p><p>The operators indulged your many questions and showed off internals like core memory modules.</p><p>For troubleshooting, they could print out (on paper) the entire contents of this core memory — a core dump.</p><p>This makes you sad.</p><p>The previous week, you observed troubling syslog entries in Kibana.</p><pre>kernel: [4838261.071917] haproxy[610]: segfault at 7fdb0426e000 ip 00007fdb0403305b sp 00007ffee5ff8988 error 4 in ld-musl-x86_64.so.1[7fdb03fe2000+87000]</pre><p>And that’s it. Segfault and no core dump. IBM 1401 operators in 1959 could get a core dump and you can’t get one out of your fancy-pants microservices platform. Why? Because Docker. Well, <a href="https://github.com/docker/docker/issues/11740">Docker on Ubuntu</a>. HAProxy runs in a Docker container on an Ubuntu host, and you can’t have nice things.</p><p>This is why you are sad. To stop being sad and get nice things, keep reading.</p><h4>microservices at Udacity</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*-3_F3SiCb6UfI2GhfZSeoA.png" /><figcaption>Udacity platform network diagram</figcaption></figure><p>Since December 2015, Udacity is transitioning from Google App Engine to a highly available microservices platform. It is <a href="http://stackshare.io/udacity/microservice-platform">state-of-the-art, infrastructure-as-code, Mesos, Docker, Consul, Weave Net (OvS), buzzword all the things</a>. The key to this transition is an HAProxy routing layer that dynamically reacts to service discovery changes and routes traffic to microservices in Docker containers on an OvS overlay network — <a href="https://youtu.be/XcI-rHO0yko?t=47s"><em>every container gets an IP</em></a>. One of those microservices is itself a router, fronting for the legacy app on GAE. In front of all that, an AWS Elastic Load Balancer keeps ingress distributed between AWS Availability Zones.</p><p>Segfaults are happening in that critical HAProxy routing layer one every five minutes on average.</p><h4>flying blind … ish</h4><p>Absent a core dump, to <a href="https://www.datadoghq.com/">DataDog</a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*knk7VhrW3GbVEaOiJ2Japw.png" /><figcaption>healthy host count over several days</figcaption></figure><p>So what happened between days 3 and 5?</p><p>A new microservice went live and a similar one a month later — you can call them Things One and Two. Each Thing serves web-hooks for Segment.io and gets lots of traffic. By overlaying DataDog graphs and request logs from Kibana, you observe correlations between segfault rates and traffic from Segment. You also see segfaults correlate to service deployments. This is telling because service deployments trigger HAProxy routing layer changes.</p><p>Since Thing One isn’t critical, you turn it off. That helps but the segfaults don’t go away and they don’t only happen near deployments. You still have no firm causal links.</p><p>If you choose to shake down Docker for a core dump, continue reading.</p><h4>shaking down docker for a core dump</h4><p>Your HAProxy servers run inside Docker containers on Ubuntu hosts and this is a problem. Since all containers share a kernel and thus kernel settings in /proc/sys, Ubuntu’s default of piping core dumps to <a href="https://wiki.ubuntu.com/Apport">Apport</a> is inflicted on all hosted containers. And, most containers don’t include Apport. To mitigate:</p><ol><li>Set /proc/sys/kernel/core_pattern to a path existing inside containers, like the process’ current directory or /tmp.</li></ol><pre>$ echo &#39;core.%e.%t.%p&#39; | sudo tee /proc/sys/kernel/core_pattern</pre><p>2. Add this flag to the docker daemon’s init so the core dump max size is unlimited. The default is zero. :/</p><pre>docker daemon [...] --default-ulimit core=-1</pre><p>Next, you create a custom haproxy container built with debug symbols, HAProxy source code, and <a href="https://www.gnu.org/software/gdb/">gdb</a>. You deploy this to a canary and wait.</p><p>While you wait for core dumps, you may want to learn more about gdb. Choose to learn more and keep reading.</p><h4>gdb</h4><p>gdb lets you see what is going on inside a program while it executes — or what the program was doing at the moment it crashed. It is the latter in which you are most interested now. A crash course on gdb <a href="https://www.youtube.com/watch?v=PorfLSr3DDI">can be completed in 15 minutes</a>; by then your core dumps will be hot and ready.</p><h4>core dumps and zlib and stacks, oh my!</h4><figure><a href="https://asciinema.org/a/8oh6i8z7whl5hzsm6y7xtfxik"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kpXvGvw-S2eLPrBu5Orp7A.png" /></a><figcaption>watch a gdb session exploring the segfault</figcaption></figure><p>The terminal recording (above) captures driving your HAProxy segfaults to root cause, teaching some gdb along the way! To summarize …</p><pre>(gdb) backtrace<br>#0  in memcpy () from /lib/ld-musl-x86_64.so.1<br>#1  in ?? () from /lib/libz.so.1<br>#2  in ?? () from /lib/libz.so.1<br>#3  in deflate () from /lib/libz.so.1<br>#4  in deflate_flush_or_finish (...) at src/compression.c:790<br>#5  in http_compression_buffer_end (...) at src/compression.c:249<br>#6  in http_response_forward_body (...) at src/proto_http.c:7173<br>#7  in process_stream (...) at src/stream.c:1939<br>#8  in process_runnable_tasks () at src/task.c:238<br>#9  in run_poll_loop () at src/haproxy.c:1573<br>#10 in main (...) at src/haproxy.c:1933</pre><pre>(gdb) frame 6<br>#6  in http_response_forward_body (...) at src/proto_http.c:7173</pre><pre>(gdb) print txn-&gt;uri<br>$3 = 0x55e95aff7a00 &quot;POST /webhook/_REDACTED_FOUR_GREAT_SECURITAH__/ HTTP/1.1&quot;</pre><pre>(gdb) frame 5<br>#5  in http_compression_buffer_end (...) at src/compression.c:249</pre><pre>(gdb) print *s-&gt;comp_algo<br>$6 = {cfg_name = 0x55e955ced5b0 &quot;gzip&quot;, ...}</pre><p><strong>The segfault is happening while gzip compressing the end of a response to <em>POST /webhook/…</em> with zlib.</strong> Every core dump you examine happens while compressing a response from service Thing Two. If you choose to fix the routing layer so malformed responses don’t crash HAProxy …</p><h4>the fix</h4><p>Memory is getting overwritten someplace in zlib. This particular segfault isn’t showing up on Stack Overflow or Google, so there may be something unique to this combination of HAproxy, zlib, musl, and specific traffic.</p><p>The stock build of HAProxy on Alpine Linux is using zlib, but that’s not the best choice. <a href="https://www.haproxy.com/doc/hapee/1.5r2/traffic_management/http_compression.html">HAProxy Enterprise Edition</a> is built with <a href="http://1wt.eu/projects/libslz/">libSLZ</a> instead, boasting impressive memory and performance benefits. And, replacing zlib with libSLZ might fix the segfaults. If you choose to build a custom HAProxy with libSLZ, <a href="https://github.com/udacity/haproxy-consul/blob/3a79197bc9100f149e94b2c13bfe601cdbc1a2e9/install-haproxy.sh">try this</a>.</p><h4>the results</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*d-gMbyuQCPm3Y6G48gg-Hw.png" /><figcaption>ELB connection errors/s</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*00dgRlxi39ZOXyuXGKSIaQ.png" /><figcaption>fix on Wed 13</figcaption></figure><h4>coda</h4><p>This issue plagued us for several months, and time from discovery to fix was long. It only took a week in total to investigate, develop a fix, canary test, and deploy, but multiple P-0s and high priority projects preempted.</p><p>The 2-level load balancing architecture only bought us time. Amazon’s ELB masked issues in the HAProxy layer, although the instability certainly had adverse effects on our <a href="https://en.wikipedia.org/wiki/Long-tail_traffic">long tail latency</a>. And as our microservices grew (we have over 100 in production), the instability grew accordingly.</p><p>Ability to debug in production is critical — it’s the only environment everyone cares about — and monitoring, metrics, and logs are necessary but not sufficient. In this brave new microservices world of “<a href="https://blog.engineyard.com/2014/pets-vs-cattle">cattle not pets</a>”, I see our industry sacrificing visibility on the altar of immutable infrastructure, <a href="https://www.joyent.com/blog/unikernels-are-unfit-for-production">naively depending on restarts as a cure-all for misbehaving services</a>. Tools to reach in and see the state of our machines are as relevant today as they were in 1959.</p><p>If you identified with this adventure, want to make a mark and build a platform with production visibility as a key concern, join us. We are a small team doing big things in a fast-paced startup.</p><p><a href="https://jobs.lever.co/udacity/7f1f2c60-4637-44ae-96f7-c92f17adc415">https://jobs.lever.co/udacity/7f1f2c60-4637-44ae-96f7-c92f17adc415</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18cc1a7e1171" width="1" height="1" alt=""><hr><p><a href="https://engineering.udacity.com/haproxy-segfault-adventure-18cc1a7e1171">an HAProxy, segfaulted, choose-your-own stack frame adventure</a> was originally published in <a href="https://engineering.udacity.com/">Udacity Eng &amp; Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[docker build containers]]></title>
            <link>https://engineering.udacity.com/docker-build-containers-6f7152ef0aec?source=rss-27e0dd974ad9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f7152ef0aec</guid>
            <category><![CDATA[udacity]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Paul Bauer]]></dc:creator>
            <pubDate>Wed, 20 Apr 2016 18:30:56 GMT</pubDate>
            <atom:updated>2018-08-07T21:55:40.840Z</atom:updated>
            <content:encoded><![CDATA[<h3>UPDATE</h3><p>As of Docker 17.05 or later, a new feature deprecates the advice in this article. If you have to use an older version of Docker, this may be a suitable strategy. Otherwise, I recommend <a href="https://docs.docker.com/engine/userguide/eng-image/multistage-build/">Multi-Stage Builds</a>.</p><h3>intro</h3><p>This is the first post in a series on how we use Docker at Udacity. It covers <strong>Docker Build Containers</strong> and was adapted from our own Docker best practices guide.</p><h3>prerequisites</h3><p>If you are new to Docker or would like a refresher on Docker concepts like images, Dockerfiles, and containers, see <a href="https://medium.freecodecamp.com/a-beginner-friendly-introduction-to-containers-vms-and-docker-79a9e3e119b">A Beginner Friendly Introduction to Containers, VMs and Docker</a> by <a href="https://medium.com/@preethikasireddy">Preethi Kasireddy</a>.</p><h4>alpine linux</h4><p>All examples use <a href="http://www.alpinelinux.org/">Alpine Linux</a>, a security-oriented, lightweight Linux distribution based on musl libc and busybox. For those familiar with debian <em>apt</em> and centos <em>yum</em>, the Alpine analog is <em>apk</em>.</p><h3>image layers</h3><p>We use Docker images for packaging, but we also use Docker containers to build the artifacts that go into the image. To understand why and how, we first need to understand Docker layers.</p><p>Docker images are typically built using an executable description called a <a href="https://docs.docker.com/engine/reference/builder/">Dockerfile</a>. Each verb in the <em>Dockerfile</em> (RUN, COPY, LABEL, etc) creates a separate layer, which has additive overhead. For more details, the official <a href="https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/">Dockerfile Best Practices</a> has advice on minimizing the number of layers.</p><p>A common Dockerfile mistake is using a separate RUN verb to cleanup temporary files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e9abb8750ebb467e630f0d258052fd6/href">https://medium.com/media/0e9abb8750ebb467e630f0d258052fd6/href</a></iframe><p>Unfortunately, we still pay the price of those cache files because layers are <em>additive</em>. The <em>RUN rm …</em> command creates a layer with tombstone files and does not remove the cached files from the previous layer. You can see this by examining <em>docker history </em>for the built image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71b7384b62a2276d01d28a72a184b414/href">https://medium.com/media/71b7384b62a2276d01d28a72a184b414/href</a></iframe><p>We need to move the cleanup <em>rm </em>to the same layer that creates the intermediate files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75e58c3ee2d1ef56d0c12a8ee2ce11d5/href">https://medium.com/media/75e58c3ee2d1ef56d0c12a8ee2ce11d5/href</a></iframe><p>Compare the docker history results with what we had before this optimization.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de1d4be4346493314022aa3fbaa6236c/href">https://medium.com/media/de1d4be4346493314022aa3fbaa6236c/href</a></iframe><h3>build containers</h3><p>A common anti-pattern is using the production Dockerfile and image to isolate builds.</p><ol><li>use RUN to install development tools</li><li>use COPY to include project source</li><li>use another RUN to build artifacts (jar, elf binary, static assets, etc)</li></ol><p>This pattern is convenient because it <em>keeps all of the build tooling self-contained</em>; the build will work on a developer laptop and on a build server without having to pre-install compilers or build tools like maven, gradle, or npm.</p><p>But all those extra bits are unused when the image is deployed to production. This is bad not just for reasons of bloat, but potential security risks. See <a href="https://en.wikipedia.org/wiki/Shellshock_(software_bug)">Shellshock</a>. And as we just saw in the layers section, we can’t use <em>RUN rm</em> to cleanup the build tools and source code later in the Dockerfile.</p><h4>example</h4><p>Here’s a golang example of what is convenient but not optimal as it keeps around intermediate build tools and source. The following is built and labeled <em>udacity/my-awesome:big</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29b63a96eb1d1697c55eb59d2f6cc6f0/href">https://medium.com/media/29b63a96eb1d1697c55eb59d2f6cc6f0/href</a></iframe><h4>enter the build container</h4><p>Instead, use the Build Container pattern. In place of one container, two are used — one for building, one for production. The build container holds all of the development or build-time bits like git and the go compiler. Built artifacts are retrieved from the build container by volume-mounting a work area. Afterwards, build artifacts are <em>COPY</em>’d into a minimal production image. Here’s a more optimal Dockerfile for our example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc52dda0fbeac693d9e72165ce18f150/href">https://medium.com/media/bc52dda0fbeac693d9e72165ce18f150/href</a></iframe><p>And here is how to use a build container to build the <em>udacity/my-awesome:1.0</em> image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f5029b873cf42ad2e7b8bcee170efaf/href">https://medium.com/media/6f5029b873cf42ad2e7b8bcee170efaf/href</a></iframe><p>The size difference between the two approaches is substantial.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4f0c5c78d6d26599bbe423793cbdc99/href">https://medium.com/media/c4f0c5c78d6d26599bbe423793cbdc99/href</a></iframe><p>This principle applies with other platforms. For example, never call <em>npm install</em> inside a production Dockerfile for a node app.</p><p>If the build container is complex or takes a long time installing dependencies, it will warrant its own image and Dockerfile.</p><h3>conclusion</h3><p>Use separate containers to isolate your project builds. The project will build as easily on a developer laptop as it does on a build server all while keeping your deployed Docker images as small as possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f7152ef0aec" width="1" height="1" alt=""><hr><p><a href="https://engineering.udacity.com/docker-build-containers-6f7152ef0aec">docker build containers</a> was originally published in <a href="https://engineering.udacity.com/">Udacity Eng &amp; Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>