<?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 Martijn Zwennes on Medium]]></title>
        <description><![CDATA[Stories by Martijn Zwennes on Medium]]></description>
        <link>https://medium.com/@martijnzwennes?source=rss-4d96a2250d44------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fvsjc0fEiajP-pzFftmQ5w.jpeg</url>
            <title>Stories by Martijn Zwennes on Medium</title>
            <link>https://medium.com/@martijnzwennes?source=rss-4d96a2250d44------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 16:01:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@martijnzwennes/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[Metaprogramming]]></title>
            <link>https://medium.com/de-bijenkorf-techblog/metaprogramming-8c477f042367?source=rss-4d96a2250d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c477f042367</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[dsl]]></category>
            <category><![CDATA[metaprogramming]]></category>
            <dc:creator><![CDATA[Martijn Zwennes]]></dc:creator>
            <pubDate>Mon, 26 Aug 2019 12:36:51 GMT</pubDate>
            <atom:updated>2019-08-26T12:36:51.008Z</atom:updated>
            <content:encoded><![CDATA[<p>Part 1: Introduction into Metaprogramming and Code generation</p><p>Just recently I was re-reading some chapters from the book: <a href="https://pragprog.com/book/tpp20/the-pragmatic-programmer-20th-anniversary-edition">The Pragmatic Programmer</a>, by Andrew Hunt and David Thomas, published in October 1999. And I stumbled onto two interesting chapters called Metaprogramming &amp; Code generators. For the ones who don&#39;t know this book I highly recommend reading it in combination with the <a href="https://www.codingblocks.net/podcast/the-pragmatic-programmer-investing-in-your-knowledge-portfolio/">Coding Blocks podcast discussion</a>.</p><p>This article will be mostly an introduction into the two topics. There will be several examples in different programming languages to help give you a better understanding of the topics, and hopefully get you excited to start using them yourself (hint: you probably already do).</p><p>Metaprogramming can help make your code contain less repetition, and improve code readability. And in some cases it can make you feel like a wizard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VaRPe46wPM5m_BLXOskkDg.jpeg" /></figure><h3>What is Metaprogramming</h3><blockquote><em>Write code that writes code — The Pragmatic Programmer (Andrew Hunt &amp; David Thomas p103)</em></blockquote><p>Metaprogramming simply means to write programs that write programs. An analogy that is often used is the car factory.</p><p>Imagine yourself as someone who builds cars, and one day you notice that the steps you are performing can be automated. So you decide to automate this process, and in the process you build a car factory. But again you notice that building your factory involves similar steps as well, so you automate them, building a factory that builds factories that builds cars. This is metaprogramming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*A9ekuHD-z2SVao5rT8ZEUQ.jpeg" /></figure><h3>Types of metaprogramming</h3><p>Metaprogramming can be handled in different steps of the processing pipeline. But overall the code is either handled during run-time (e.g. <a href="https://www.javatpoint.com/java-reflection">Java Reflection</a> or <a href="https://en.wikipedia.org/wiki/Monkey_patch">monkey patching</a>), or compile-time processing (e.g. <a href="http://www.cplusplus.com/doc/oldtutorial/templates/">C++ templates</a>, and <a href="https://en.wikipedia.org/wiki/Macro_(computer_science)">macros</a>).</p><p>Don’t worry if some of these terms are not familiar. This article contains descriptions and examples to most of the topics mentioned above.</p><h3>Use cases</h3><p>The idea might still be a bit abstract so lets start with some use cases that might be worth using metaprogramming for:</p><ul><li>Generating domain models (structs, classes, SQL code) based on configuration files (e.g. generating Kotlin data classes and JavaScript classes based on SQL tables)</li><li>Generating boilerplate for different languages (e.g. <a href="https://grpc.io/">gRPC</a> can generate domain models and interfaces in multiple programming languages based on simple service definitions)</li><li>Migrating codebases from one language to another</li></ul><h3>Examples of metaprogramming</h3><p>Metaprogramming is used in almost every programming language out there. Popular examples of metaprogramming are:</p><ul><li>Annotations</li><li>Domain Specific Languages (DSLs)</li><li>Macros</li><li>Interpreters</li><li>Compilers</li></ul><p>Lets get started with some examples.</p><h3>Annotations</h3><p>Java’s annotations are a good example of metaprogramming. The Java language allows adding annotations to packages, classes, interfaces, methods, or fields. These annotations can either extend the language during compile time (compile-time instructors), or during runtime (runtime instructors).</p><p>A simple Java annotation example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a3387a88cd25465dc56e1bbd3103061/href">https://medium.com/media/0a3387a88cd25465dc56e1bbd3103061/href</a></iframe><p>The @Test annotation tells the testing framework that the attached method can be run as a test case.</p><h3>Domain Specific Languages (DSLs)</h3><p>Domain specific languages are custom made (mini-)languages which are designed for a particular application domain. There are two kinds of DSLs: external and internal.</p><p>External DSLs are custom languages that are parsed independent of the language it’s written in. A well-known example of an external DSL is SQL, it’s a language specialized for talking to databases.</p><p>Internal DSLs are similar to external DSLs, with the exception that they are bound to the language in which they are written. Rather then creating a new language, they extend an existing language.</p><p>Kotlin offers some nice features that allow programmers to create their own mini languages inside of the JVM.</p><p>For instance you could write a small DSL to create web API’s:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/357f276dc56ca7d5b1a4bdaf13f1f2c1/href">https://medium.com/media/357f276dc56ca7d5b1a4bdaf13f1f2c1/href</a></iframe><p>In the example above we are using constructs such as: database, api, and get. These constructs are not available in the Kotlin language, but they can be created by extending the language using some of it&#39;s capabilities.</p><p>The example above can be implemented using the following constructs (this only implements the syntax, not the actual database and API):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93ee9edf038930298a6f637d0faec68c/href">https://medium.com/media/93ee9edf038930298a6f637d0faec68c/href</a></iframe><p>With <a href="https://github.com/juanchosaravia/autodsl">AutoDsl</a> we can even shorten this example by using some predefined Annotations:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/194cf108cbbe24cc8dd9b83010630ca7/href">https://medium.com/media/194cf108cbbe24cc8dd9b83010630ca7/href</a></iframe><p>This looks way cleaner! AutoDsl will create the lowercase functions and even generates builders in order for the application to be Java compatible.</p><h3>Macros</h3><p>Languages such as Lisp, Clojure, Scala, Rust, and many others offer a system called macros to extend the capabilities of the language. And if you ever wrote a hello world application in Rust then you have used them before:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f074994a13fc2a37168acc82b1ffea3/href">https://medium.com/media/2f074994a13fc2a37168acc82b1ffea3/href</a></iframe><p>Macros in Rust can be spotted by the ! character. They are similar to function calls but they work slightly different. Some examples of things that just can&#39;t be done with functions:</p><ul><li><strong>Pretty syntax</strong> — Macros allow you to extend the language with additional syntax.</li><li><strong>Meta-programming</strong> — Macros can be used to generate functions.</li><li><strong>Variadic arguments</strong> — Macros can take a variable number of arguments.</li></ul><h4>Example 1: Writing Scala in Rust</h4><p>Lets try to get a deeper understanding of macros by starting with an example. Imagine you have been working in a Scala code base for ages, and recently you moved over to Rust. But for some reason you keep using the Scala syntax to define functions.. well, no problem, just add a macro!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1149b095014e26654c7b94d0caf08e3d/href">https://medium.com/media/1149b095014e26654c7b94d0caf08e3d/href</a></iframe><p>A lot is going on here so let me try to explain the example given above. Macros are defined using the macro_rules! expression (which is a macro itself).</p><p>A macro can contain one or more arms where each arm signifies a pattern which can be matched. The macro will take the input which is given and tries to fit it to each matcher. If the signature of the match is valid, then the body of the arm is executed.</p><p>Multiple arms can be defined by using the () =&gt; (); syntax. In the example our arm has the following signature: (def $name:ident = $e:expr). Here we have two variable names: $name, and $e. And two additional values called: ident and expr. These values are called metavariables.</p><p>Instead of types, macros use a thing called metavariables, these metavariables have fragment specifiers, identifying which syntactic form it matches.</p><p>Some examples of fragment specifiers are</p><ul><li>ident: an identifier. Examples: x; foo.</li><li>expr: an expression. Examples: 2 + 2; if true { 1 } else { 2 }; f(42).</li><li>tt: a single token tree.</li></ul><p>Macros in Rust get parsed as full abstract syntax trees (AST). These trees are representations of the structure of your program.</p><p>For example, 2 + 3 can be turned into a tree:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48ab00445e12be522440fb223d2c1c10/href">https://medium.com/media/48ab00445e12be522440fb223d2c1c10/href</a></iframe><p>And 2 + (3 * 4) would look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e38f2d5714bbb7aa922a75ee9565763/href">https://medium.com/media/3e38f2d5714bbb7aa922a75ee9565763/href</a></iframe><p>I won’t expand further on them in this article to avoid diving to deep into the rabbit hole, but I <a href="https://en.wikipedia.org/wiki/Abstract_syntax_tree">suggest the wiki</a> if you wish to learn more about them. In part two of this series we will go deeper into abstract syntax trees.</p><h3>Example 2: Implementing parts of JSX in Rust</h3><p>So maybe the scala! macro is not a super useful example, but it is a nice way to show what macros can do. It actually only takes around 380 lines of code to implement a <a href="https://github.com/JunSuzukiJapan/macro-lisp">lisp-like DSL in Rust</a>.</p><p>A somewhat more useful example would be to create a macro that allows creating HTML templates in a similar fashion to <a href="https://reactjs.org/docs/introducing-jsx.html">JSX</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03ac67b8c47c3beeb5b72bbcf630e8c4/href">https://medium.com/media/03ac67b8c47c3beeb5b72bbcf630e8c4/href</a></iframe><p>This will print the following result:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15038211971d8b7cc19bf0cc716f090d/href">https://medium.com/media/15038211971d8b7cc19bf0cc716f090d/href</a></iframe><p>And this functionality is actually implemented using only 11 lines of code within a single macro:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5fd9769a474814c71e3ffa7ac16ee61/href">https://medium.com/media/e5fd9769a474814c71e3ffa7ac16ee61/href</a></iframe><p>There is still quite some functionality missing in this macro, but it does show that macros can be a powerful tool. The actual implementation for JSX-like syntax in Rust is actually <a href="https://github.com/bodil/typed-html">already available as a crate</a>.</p><h3>Conclusion</h3><p>In this article we looked at different implementation of metaprogramming in several languages. And we went over examples of annotations, reflection, DSL, and macros. Personally I feel that having these tools in my tool belt allows me to write code that contains less duplication, and allows more flexibility in the written code. Hopefully you feel the same way.</p><p>In the next article we will go deeper into abstract syntax trees, learn more about procedural macros, and write an application that can cross-compile to different programming languages. Stay tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c477f042367" width="1" height="1" alt=""><hr><p><a href="https://medium.com/de-bijenkorf-techblog/metaprogramming-8c477f042367">Metaprogramming</a> was originally published in <a href="https://medium.com/de-bijenkorf-techblog">De Bijenkorf — Design and Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying machine learning models with Kubeflow]]></title>
            <link>https://medium.com/de-bijenkorf-techblog/deploying-machine-learning-models-with-kubeflow-b2cb45cf22f5?source=rss-4d96a2250d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2cb45cf22f5</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubeflow]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Martijn Zwennes]]></dc:creator>
            <pubDate>Wed, 08 May 2019 14:46:07 GMT</pubDate>
            <atom:updated>2019-05-08T14:46:41.322Z</atom:updated>
            <content:encoded><![CDATA[<h4>From manual deployments to scalable Kubernetes deployments with Kubeflow</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*JZs9F24-kZnXsQUgGjL_VQ.png" /></figure><p>Written by <a href="https://medium.com/u/e917e5fc7bc3">Tim Nooren</a> &amp; <a href="https://medium.com/u/4d96a2250d44">Martijn Zwennes</a></p><p>Around five years ago we started out with a really small data team. That team consisted of around four people (analysts and data engineers), and their job was to support all the other teams with reports and insights. We owned a single database which held all the data and analysts performed queries on this database to create their reports. Life was limited, but easy.</p><p>Slowly we started scaling; The single database scaled to a clustered solution, multiple reporting tools were integrated, and a large number of teams got introduced that required their own reporting &amp; analysis. This kind of analysis often required machine specs that were not currently present. In this post we will explain how we went from setting up machines manually to ultimately deploying the models with Kubernetes (and potential next steps).</p><h3>Manual deployments</h3><p>We started out with manually spinning up a machine on Amazon Web Services (AWS) or Google Cloud Platform (GCP). Once an analyst wanted to run a model on a bigger machine he/she would choose some specs, spin up the machine, open some ports, install Jupyter notebooks (optional), write the code, and finally run the model. Obviously this method is not ideal due to numerous reasons:</p><ul><li>Security issues — No control over ports/access</li><li>Costs — Big chance of over-provisioning resources</li><li>Costs — No guarantee the machine is stopped/killed once the task is completed</li><li>Setup time — All these manual steps can take time &amp; mistakes can be made</li><li>Flexibility — Moving models to production can be quite cumbersome</li><li>Monitoring — No centralized logging &amp; monitoring</li><li>Workflow — Hard to execute tasks on a separate machine that are part of a bigger workflow</li></ul><h3>Bokchoi</h3><p>To tackle some of these issues we initially wrote a tool called Bokchoi that allows users to start a machine in the cloud (using spot instances/pre-emptibles to keep the cost down), deploy their code and either start a Jupyter notebook or execute a specific script, all with a few simple commands and without having to interact with the cloud provider directly. The entire local project directory is mirrored on the cloud machine to make the transition as seamless as possible.</p><p>By using Bokchoi we could schedule workloads on much bigger machines, have them run at night and at reduced cost. Although useful in the early stage of getting a model up and running quickly, at some point we found that we had a number of different deployments running but no real way of monitoring them, since there existed no centralized overview of all applications.</p><p>Bokchoi did solve some issues surrounding the initial setup and stopping a machine after a task was finished, unfortunately the rest of the issues remained.</p><h3>Kubernetes</h3><p>With the rest of our infrastructure gradually moving to Kubernetes we saw an opportunity to run our models in the same fashion. Since we already had a few Kubernetes clusters running we could easily start preparing our models to allow running there. The overall flow would look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*hEt824yINOcWIjDutWcOaA.png" /><figcaption>A typical Kubernetes deployment</figcaption></figure><p>Kubernetes (cron-)jobs are a nice solution when there is a single script or task which you would want to execute on a regular base. Since the executable is a Docker image, we could easily create a model this way. Kubernetes also provides us with a single overview of all deployments and their schedule, as well as centralized monitoring, logs and alerts.</p><h3>Hello World Kubernetes Job</h3><p>The following code snippets shows a quick hello world example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91bfe685cac475cbeabd5abb9c8db42b/href">https://medium.com/media/91bfe685cac475cbeabd5abb9c8db42b/href</a></iframe><p>Once we got the code, we need to build a Docker image for the script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef91e37b2b31fe360ba8386586ffde6f/href">https://medium.com/media/ef91e37b2b31fe360ba8386586ffde6f/href</a></iframe><p>Once built we can push the image to our container registry (we are using Google Container Registry):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b33e819e00bca27aa008ec7d83febbcd/href">https://medium.com/media/b33e819e00bca27aa008ec7d83febbcd/href</a></iframe><p>And lastly we can set up a small Kubernetes job (I excluded some attributes for readability, check the docs here: <a href="https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/">https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/</a>):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f245ec36c221899fb4d63fa7b033ee7/href">https://medium.com/media/3f245ec36c221899fb4d63fa7b033ee7/href</a></iframe><p>The job can be executed by running kubectl apply -f hello-world-tf.yaml.</p><p>Kubernetes jobs are perfectly adequate for a simple hello world examples such as above. Nevertheless we encountered some difficulties with using the Kubernetes API directly once our models got a bit more complex. One of the issues we encountered when running jobs directly on Kubernetes is that the complexity of the training process quickly increases when additional steps are needed like data extraction, data preparation, model testing or post-processing. Often data science code consists of scripts rather than full-fledged applications, and combining all these functions in a single script does not yield the greatest code.</p><h3>Kubeflow</h3><p>Kubeflow’s goal is to simplify deploying machine learning workflows to Kubernetes. Currently it consists of a number of different services that give you the tools you need to develop, train, test and deploy models without having to worry (much) about Kubernetes’ internals. We currently use two services specifically: the Jupyter hub for developing models and Pipelines for creating and scheduling workflows.</p><p>This is where Kubeflow Pipelines offers a solution. Pipelines provides a simple set of commands to chain together different operations and pass data between them. Separating each operation into its own container greatly reduces the overall complexity. Additionally this gives you the freedom the choose different frameworks or languages for different steps. You could prepare your data using Pandas in Python and but write your model in R for instance. This also encourages sharing and reuse of common operations, such as loading from object storage or writing to databases.</p><h3>Setup</h3><p>Setting up Kubeflow can be done either through the GUI (only supports Google Cloud) or CLI. If you just want to play around with Kubeflow we recommend using the <a href="https://deploy.kubeflow.cloud/#/deploy">GUI which can be found here</a>, but once you want to do a actual permanent deployment we recommend <a href="https://www.kubeflow.org/docs/gke/deploy/deploy-cli/">using the CLI.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zAeZ9nRub8498OJE4R5GOA.png" /><figcaption>Screenshot of the Kubeflow deployment via <a href="https://deploy.kubeflow.cloud/#/">https://deploy.kubeflow.cloud/</a></figcaption></figure><p>The GUI deployment missed a few things which made us to go for the CLI deployment. For starters the initial deployment is deployed with standard machines, where we wanted to run the complete environment on pre-emptibles. Pre-emptibles are machines that can be killed after 24 hours, but only cost 20% of the price of standard instances. Another addition we really wanted was support for GPU machines (and yes you guessed correct, also pre-emptible because we love our cheap stuff ). 💵 💵</p><h3>Example</h3><p>To show the strength of Kubeflow Pipelines we’ll modify the Kubernetes example a little by including a pre-processing step, where we generate the text that we’ll read in the next step. In reality the first step might be where you prepare your data set and the second step where you train your model.</p><p>Let’s write a script called generate.py that writes a string to a file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86f8e3e98817ebdf2a42c1a0968c0e0b/href">https://medium.com/media/86f8e3e98817ebdf2a42c1a0968c0e0b/href</a></iframe><p>And a script called consume.py that reads a file and outputs its contents:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14e17095f1d2a145a0f126cad85fbd96/href">https://medium.com/media/14e17095f1d2a145a0f126cad85fbd96/href</a></iframe><p>Again we wrap these scripts in a Docker image:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8dc23ca0b38fcab513d65b575dc0098/href">https://medium.com/media/a8dc23ca0b38fcab513d65b575dc0098/href</a></iframe><p>and push it to our container repository:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65f0d1c02993076c2e35da8170075690/href">https://medium.com/media/65f0d1c02993076c2e35da8170075690/href</a></iframe><p>With Kubeflow Pipelines we can now define a workflow that runs both images as separate steps and passes the output from the first step to the second, storing the intermediate result as an artifact in object storage. In this case we’re using minio, which is deployed with Kubeflow, but you could just as easily use S3 or Google Storage. We define the task dependencies in a directed acyclic graph (DAG), which is also used to map the output of the first step to the input of the second step.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6de428d0c824ac9f902ad9c02e081346/href">https://medium.com/media/6de428d0c824ac9f902ad9c02e081346/href</a></iframe><p>When we upload this definition we can see Pipelines understands our desired workflow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z5iaX83AIh-Hsw0oheXpbw.png" /><figcaption>Example of the workflow graph</figcaption></figure><p>And running yields the desired output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JOFQZtIZ0AnBH4dv8y4mRQ.png" /><figcaption>Results for the graph shown above</figcaption></figure><p>This simple example shows the flexibility of piecing together simple building blocks in the form of Docker containers to create complex workflows. The DAG allows for much more intricate control flows by running steps in parallel, combining outputs across multiple execution steps, etc.</p><h3>Next steps</h3><p>We still haven’t touched some of the other features of Kubeflow, and new features are coming out regularly. Some of the ones we’re excited about:</p><ul><li>Katib is Kubeflow’s engine for hyper-parameter optimization. We’re looking into combining Katib with our pipelines so we can define our workflow and then use Katib to find an optimal set of parameters. By using pipelines you could optimize any setting in any of step of your workflow, whether it’s the actual model training, or some pre-processing step.</li><li>The Python DSL for generating pipeline definitions looks promising, allowing pipeline definitions to be built up by combining modular building blocks. Common patterns could be centralized reused, reducing the lines of code needed for each definition (the raw YAML can get quite lengthy).</li><li>Seldon can be used for deploying and serving models and offers components for things like A-B testing and multi-armed bandit experiments.</li></ul><h3>Conclusion</h3><p>All in all we’re very excited about Kubeflow. It has allowed us to make our ML pipelines much more production worthy and by picking and choosing from the different services it provides we can build out gradually.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2cb45cf22f5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/de-bijenkorf-techblog/deploying-machine-learning-models-with-kubeflow-b2cb45cf22f5">Deploying machine learning models with Kubeflow</a> was originally published in <a href="https://medium.com/de-bijenkorf-techblog">De Bijenkorf — Design and Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Speed up application launch time with GraalVM]]></title>
            <link>https://medium.com/de-bijenkorf-techblog/speed-up-application-launch-time-with-graalvm-3d629131adb1?source=rss-4d96a2250d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d629131adb1</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[graal]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[substratevm]]></category>
            <dc:creator><![CDATA[Martijn Zwennes]]></dc:creator>
            <pubDate>Thu, 06 Dec 2018 11:01:51 GMT</pubDate>
            <atom:updated>2019-01-10T14:38:10.491Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qDX6Hd8ivSkA0UmuEH0LiQ.jpeg" /></figure><h4>Introduction to GraalVM</h4><p>In the past few months we have made great progress in regards to infrastructure. Where we started with manual configured applications running on compute engines and Elastic Beanstalk, we are now running multiple Kubernetes clusters with the entire infrastructure in code, ready to be re-deployed again.</p><p>During the dockerization and setting up the Kubernetes deployments we learned that:</p><ul><li>Java needs some tweaking to work properly with Docker <br><em>Some optimizations have been made in Java 10 that are enabled by default in Java 11 </em><em>-XX:-UseContainerSupport️.</em></li><li>Startup time of your application is crucial to allow fast scaling.</li><li>The overall memory footprint of applications/frameworks can be quite large nowadays.</li></ul><p>On a quest to look for solutions to these problems, and while secretly looking for new things because new is always better, I encountered GraalVM. Which is a replacement Java Hotspot VM (JVM) that is developed by Oracle. It’s also noteworthy that the the Graal compiler has been made available as an experimental option in JDK 10.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*8rYB5WqHRBw8i4pqQJGkwQ.gif" /><figcaption>New is always better — Barney Stinson — How I met your mother</figcaption></figure><p><strong>GraalVM</strong></p><p>GraalVM is a high performance embeddable polyglot virtual machine that supports applications written in JavaScript, Python, Ruby, R, JVM-based languages like Java, Scala, Clojure, Kotlin, and LLVM-based languages such as C and C++.</p><p>SubstrateVM (part of GraalVM) is a native virtual machine that allows you to compile your Java programs ahead-of-time into a native executable. The resulting program does not run on the Java HotSpot VM, but uses necessary components like memory management, thread scheduling from a different implementation of a virtual machine, called Substrate VM. Substrate VM is written in Java and compiled into the native executable. The resulting program has significantly faster startup time and lower run-time memory overhead compared to a Java VM.</p><p><strong>How does this work?</strong></p><p>GraalVM uses aggressive static analysis during the ahead-of-time compilation which requires a closed-world assumption. This means that all the required classes should be reachable at run time. Therefore using frameworks that depend heavy on reflection are relatively painful/impossible to convert to native images with GraalVM. Substrate VM has partial support for reflection which is resolves through static analysis by looking for code that calls the reflection API.</p><p><strong>Real life scenario</strong></p><p>Now lets try running simple Kotlin API that exposes product inventory from a Redis back-end. For this simple exercise I’ve chosen the Spark library due to it’s ease of use and minimal boilerplate.</p><p>A complete example with all the code included can be found in <a href="https://github.com/zwennesm/spark-redis-graalvm-demo">this Github repository</a>.</p><p>Lets start with adding dependencies:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5573bfa5015fc3a7506e2c11e7d681c7/href">https://medium.com/media/5573bfa5015fc3a7506e2c11e7d681c7/href</a></iframe><p>Then create a new class and add the following example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1bb89840ee8ca0da0a131953b571850/href">https://medium.com/media/b1bb89840ee8ca0da0a131953b571850/href</a></iframe><p>Once this is done we can create a fat application containing all the dependencies. For this I’ve chosen to use the com.github.johnrengelman.shadow plugin.</p><p>Just make sure to have a Redis instance running on localhost. I’m using a Docker container for just this purpose:</p><pre>docker run -p 6379:6379 --name some-redis -d redis</pre><p>Test if the application is working by running the fatJar command and then run the application using java.</p><pre>./gradlew clean fatJar</pre><pre>java -jar build/libs/ceres-inventory-all-deps-0.0.1.jar</pre><pre>2018–12–03 18:33:43 INFO EmbeddedJettyServer:127 — == Spark has ignited …</pre><pre>2018–12–03 18:33:43 INFO EmbeddedJettyServer:128 →&gt; Listening on 0.0.0.0:4567</pre><pre>2018–12–03 18:33:43 INFO Server:444 — Started @463ms</pre><p>Awesome that works! 🎆</p><p>Finally we can use the command to build the native executable. I used graalvm-ce-1.0.0-rc9-linux-adm64 for this post.</p><pre>native-image \<br>    -class-path build/libs/ceres-inventory-all-deps-0.0.1.jar \    <br>    -H:EnableURLProtocols=http \     <br>    -H:IncludeResources=”log4j.properties” \<br>    -H:Name=inventory \<br>    -H:Class=inventory.ApplicationKt \<br>    -H:+ReportUnsupportedElementsAtRuntime \<br>    -H:+AllowVMInspection</pre><p>Warning: running the command above could take some time and might result in some high temperatures 🔥 🔥. During this step, SubstrateVM will compile your application using it’s ahead-of-time compiler. This is a CPU/memory intensive process.</p><p><strong>Startup time</strong></p><p>Once the application has been compiled you will see that a binary file has been created. Just run the application like any other by running:</p><pre>./inventory</pre><pre>2018–12–03 16:04:30 INFO EmbeddedJettyServer:127 — == Spark has ignited …</pre><pre>2018–12–03 16:04:30 INFO EmbeddedJettyServer:128 →&gt; Listening on 0.0.0.0:4567</pre><pre>2018–12–03 16:04:30 INFO Server:444 — Started @7ms</pre><p>The app went from starting in 463ms to a whopping 7ms, awesome!</p><p><strong>Memory footprint</strong></p><p>The other problem that we’re trying to tackle is the memory requirement for the application. To measure the memory footprint, I use a simple tool called /usr/bin/time. You can read more about it <a href="https://stackoverflow.com/questions/19494298/how-does-usr-bin-time-measure-memory-usage">here</a>. The results are astonishing!</p><p>With the Java Hotspot VM:</p><pre>/usr/bin/time -f “\nmaxRSS\t%MkB” java -jar build/libs/ceres-inventory-all-deps-0.0.1.jar</pre><pre>maxRSS 215924kB</pre><p>With the native executable:</p><pre>/usr/bin/time -f “\nmaxRSS\t%MkB” ./inventory</pre><pre>maxRSS 18104kB</pre><p>As you can see the memory usage went from 215.924kB to 18.104kB 👊</p><p><strong>Afterthoughts<br></strong>Although I have only tried this with Spark, other web frameworks such as Micronaut and Vert.x also seem to support GraalVM with some minor tweaking. Spring however depends deeply on reflection which makes it hard/impossible to use with GraalVM for now (compilation to a native image that is).</p><p>The issue with reflection will be a major problem for many existing applications. But GraalVM can be a great addition for new applications (and many new Kotlin applications).</p><p>In this post we skimmed over the surface of GraalVM and SubstrateVM. Personally I am pretty positive about the results and I am a big fan of the option to create native executables.</p><p><strong>Related links</strong></p><ul><li><a href="https://medium.com/graalvm/instant-netty-startup-using-graalvm-native-image-generation-ed6f14ff7692">Another example using Netty</a></li><li><a href="http://www.ssw.uni-linz.ac.at/Research/Papers/Stadler14/Stadler2014-CGO-PEA.pdf">Graal research paper</a></li><li><a href="https://github.com/oracle/graal/blob/master/substratevm/REFLECTION.md">Using reflection with GraalVM</a></li><li><a href="https://github.com/zwennesm/spark-redis-graalvm-demo">Code used in this post</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d629131adb1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/de-bijenkorf-techblog/speed-up-application-launch-time-with-graalvm-3d629131adb1">Speed up application launch time with GraalVM</a> was originally published in <a href="https://medium.com/de-bijenkorf-techblog">De Bijenkorf — Design and Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>