<?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 Daniel Alejandro Coll Tejeda on Medium]]></title>
        <description><![CDATA[Stories by Daniel Alejandro Coll Tejeda on Medium]]></description>
        <link>https://medium.com/@danielalecoll?source=rss-1013236d8049------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*O5z-1Ezu6oq4F4g-oZ_tFQ.jpeg</url>
            <title>Stories by Daniel Alejandro Coll Tejeda on Medium</title>
            <link>https://medium.com/@danielalecoll?source=rss-1013236d8049------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 23:32:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danielalecoll/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[Effortless Serverless Python: Get Your Code Running in the Cloud in 3 Clicks with PyRun]]></title>
            <link>https://danielalecoll.medium.com/effortless-serverless-python-get-your-code-running-in-the-cloud-in-3-clicks-with-pyrun-4c3d9537cfd3?source=rss-1013236d8049------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c3d9537cfd3</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pyrun]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Daniel Alejandro Coll Tejeda]]></dc:creator>
            <pubDate>Fri, 11 Jul 2025 08:03:49 GMT</pubDate>
            <atom:updated>2025-07-11T08:03:49.238Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0VAOX2LynGbsxxkGH2Nyg.png" /><figcaption>PyRun UI</figcaption></figure><p>Let’s be honest: running Python code in the cloud can be a headache. You write a brilliant script for data processing, an AI model, or a scientific simulation, only to face the mountain of setting up servers, managing dependencies, configuring security groups, and wrestling with cryptic YAML files. Your focus shifts from your code to the complex world of cloud infrastructure.</p><p>What if you could skip all that? What if you could take your Python script and run it at scale in the cloud, with all the setup handled for you, in just a few minutes?</p><p>Meet <a href="https://pyrun.cloud/"><strong>PyRun</strong></a>, a platform designed to do exactly that. It democratizes cloud computing for Python users by automating the hard parts, letting you focus on what truly matters: your code.</p><p>This article will show you what PyRun is and how you can get your first serverless application running on your own AWS account in literally three clicks.</p><h3>What is PyRun (and Why Should You Care)?</h3><p>At its core, <strong>PyRun is a platform that automates the complexities of running Python code in the cloud.</strong> It provides a simplified, integrated environment so you can focus on your code, not on cloud infrastructure.</p><p>Think of it as the ultimate control panel for your own cloud account. It provides:</p><ul><li><strong>A VS Code-like Web Interface:</strong> Write code, manage files, and monitor jobs all in one place. No more switching between your local IDE, a terminal, and the AWS console.</li><li><strong>Automated Runtimes:</strong> Simply define your packages in an <em>environment.yml</em> file. PyRun automatically builds your environment in the cloud. Need a system-level tool? Use a <em>Dockerfile</em> instead. It’s that simple.</li><li><strong>Seamless Framework Integration:</strong> PyRun offers first-class support for powerful tools like <a href="https://lithops.cloud/"><strong>Lithops</strong></a> (for massively parallel serverless functions) and <a href="https://www.dask.org/"><strong>Dask</strong></a> (for scalable data science). It handles the complex backend configuration so you can just use them.</li><li><strong>Execution on <em>Your</em> Cloud Account:</strong> This is key. PyRun orchestrates the work, but the code runs securely within your own AWS account. You maintain full control and transparency over your resources and costs.</li></ul><p>In short, PyRun bridges the gap between your Python script and the immense power of the cloud, removing nearly all the friction.</p><h3>The 3-Click Setup: Connecting PyRun to Your AWS Account</h3><p>Ready to see how easy it is? Let’s get you set up. This is a one-time process that takes about two minutes.</p><p><strong>What you’ll need:</strong></p><ul><li>An email address</li><li>An AWS account. (If you don’t have one, you can <a href="https://aws.amazon.com/free/">create one here</a>).</li></ul><h3>Step 1: Sign Up for PyRun</h3><p>First, head to the <a href="https://app.pyrun.cloud/signup">PyRun signup page</a> and create your account with a unique username.</p><h3>Step 2: Connect to AWS</h3><p>Once you’re logged in, go to the “Cloud Account” section in the PyRun dashboard and click the big blue <strong>“Connect to AWS”</strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wz4dlSy3-vhodD9Zm6lBEw.png" /><figcaption>Cloud Account section on PyRun</figcaption></figure><p>This will prompt you to click <strong>“Take me to CloudFormation”</strong>.</p><blockquote><strong><em>Why CloudFormation?</em></strong><em><br>This is the magic of the secure, one-click setup. PyRun uses AWS CloudFormation (Infrastructure-as-Code) to create a specific IAM role with the </em>minimum necessary permissions<em> in your account. This allows PyRun to manage resources (like starting Lambda functions for your jobs) </em>on your behalf<em> without ever needing your secret keys. It’s the standard, secure way to grant access.</em></blockquote><h3>Step 3: Create the Stack</h3><p>You’ll be redirected to the AWS CloudFormation “Quick create stack” page. All the necessary configurations are pre-filled.</p><ol><li>Scroll to the bottom.</li><li>Check the box acknowledging that CloudFormation will create IAM resources.</li><li>Click <strong>“Create stack”</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sfQVqAyE9fYoRkXpwDLwYA.png" /><figcaption>CloudFormation example interface</figcaption></figure><p>That’s it! AWS will now create the necessary resources, which usually takes a minute or two. Once it’s done, your PyRun dashboard will show that your account is connected.</p><p>You just set up a scalable serverless environment in three clicks.</p><h3>Running Your First Serverless Application</h3><p>Now that you’re set up, let’s run some code. We’ll use a <strong>Lithops</strong> template to execute a simple Python function in parallel across multiple AWS Lambda invocations.</p><h4>1. Create a Workspace</h4><p>In PyRun, a <strong>Workspace</strong> is your project environment.</p><ol><li>Go to the “Workspaces” section and click “Create new workspace”.</li><li>Select the <strong>“Lithops”</strong> template. This gives you a pre-configured environment for serverless computing.</li><li>Give it a name and click “Run”.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gtWdhLszXAn0_iWtnfPCVg.png" /><figcaption>UI for creating a workspace in PyRun</figcaption></figure><h4>2. Check Out the Code</h4><p>Your new workspace comes with an <em>example.py</em> file. Let’s look at the code:</p><pre>import lithops<br>import time<br><br><br>def my_map_function(id, x):<br>    print(f&quot;I&#39;m activation number {id}&quot;)<br>    time.sleep(5)<br>    return x + 7<br><br><br>if __name__ == &quot;__main__&quot;:<br>    iterdata = [10, 11, 12, 13]<br>    fexec = lithops.FunctionExecutor()<br>    fexec.map(my_map_function, iterdata)<br>    print(fexec.get_result())</pre><p>This script defines a simple function <em>my_map_function</em> and uses <em>fexec.map()</em> to run it in parallel for each item in the <em>iterdata</em> list. Lithops will take care of invoking four separate AWS Lambda functions to execute this work concurrently.</p><h4>3. Run and Monitor!</h4><p>Now for the best part. <strong>Just click the “Run” button.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CeiTliLLSyuC79P9cSo93w.png" /><figcaption>Run button on VSCode inteface</figcaption></figure><p>PyRun takes over. It packages your code, sends it to Lithops, which then invokes multiple parallel AWS Lambda functions on your behalf. You didn’t have to configure a single function, upload any code to S3, or set any timeouts. It just works.</p><p>As it runs, you can switch to the <strong>Monitoring</strong> tab to see real-time graphs of CPU, memory, and network usage across all your parallel functions. You get a god-mode view of your distributed computation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OdTaxSamrUMHZ_yOKy0oAg.png" /><figcaption>Real Time monitoring overview</figcaption></figure><p>Once the job is complete, the results (<em>[17, 18, 19, 20]</em>) will be printed in the logs.</p><h3>What’s Next?</h3><p>You’ve just scratched the surface. From here, you can:</p><ul><li><strong>Customize Your Environment:</strong> Add any package you need to <em>.pyrun/environment.yml</em>, and PyRun will automatically rebuild your runtime.</li><li><strong>Explore Pipelines:</strong> Run pre-built, real-world examples for things like hyperparameter tuning, geospatial analysis, or processing climate data from the “Pipelines” section.</li><li><strong>Scale with Dask:</strong> Create a Dask workspace to parallelize your pandas and scikit-learn workflows on a cloud-based cluster.</li><li><strong>Manage Data:</strong> Use the <strong>Data Cockpit</strong> to easily select, partition, and feed data from S3 into your parallel jobs.</li></ul><h3>Conclusion</h3><p>You just went from zero to running a scalable, serverless Python application in the cloud. And you did it without writing YAML, configuring services in the AWS console, or even opening your local terminal.</p><p>This is the power of PyRun. It lowers the barrier to entry for powerful cloud computing, allowing developers and data scientists to solve bigger problems faster. Whether you’re processing geospatial data, tuning hyperparameters, or running financial models, PyRun provides the simplest path to leveraging the cloud’s infinite scale.</p><p>Stop wrestling with infrastructure and start running your code.</p><p><strong>Ready to try it out?</strong></p><ul><li><a href="https://pyrun.cloud/">Get started with PyRun</a></li><li><a href="https://docs.pyrun.cloud/">Check out our documentation</a> for more examples and guides.</li><li><a href="https://discord.gg/AF9XBqbxRS">Join our Discord Community</a> for help and discussion.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c3d9537cfd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beyond ‘Hello World’: Powering Real-World Science and AI with PyRun]]></title>
            <link>https://danielalecoll.medium.com/beyond-hello-world-powering-real-world-science-and-ai-with-pyrun-4a5878278ddf?source=rss-1013236d8049------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a5878278ddf</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[serveless]]></category>
            <category><![CDATA[pyrun]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Daniel Alejandro Coll Tejeda]]></dc:creator>
            <pubDate>Fri, 11 Jul 2025 08:03:39 GMT</pubDate>
            <atom:updated>2025-07-11T08:03:39.113Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iBSxhzDxdPlcYXfpD0aeRQ.png" /><figcaption>Pipelines section on PyRun</figcaption></figure><p>In my last post, we saw how ridiculously easy it is to <a href="https://medium.com/@danielalecoll/effortless-serverless-python-get-your-code-running-in-the-cloud-in-3-clicks-with-pyrun-4c3d9537cfd3">get PyRun up and running</a> and execute a simple parallel script in the cloud. You clicked a few buttons, and suddenly you were harnessing the power of AWS Lambda without writing a single line of infrastructure code.</p><p>But real-world data science, AI, and research are rarely that simple. Your projects have dependencies. You need specific versions of <em>TensorFlow</em>, <em>Rasterio</em> for geospatial data, or maybe the latest transformers library. And you want to solve complex problems, not just add 7 to a number.</p><p>This is where <a href="https://pyrun.cloud/">PyRun</a> truly shines. It’s not just for simple scripts; it’s a full-fledged platform designed to handle the complexity of modern computational work with the same simplicity we saw before.</p><p>Today, we’ll level up. We’ll explore two of PyRun’s most powerful features:</p><ol><li><strong>Custom Runtimes:</strong> How to effortlessly create a custom Python environment with all the packages you need.</li><li><strong>Pipelines:</strong> Ready-to-run, end-to-end examples that solve complex problems in AI, metabolomics, and geospatial analysis, which you can launch with a single click.</li></ol><h3>Part 1: Mastering Your Environment, The Easy Way</h3><p>In the world of cloud computing, the “runtime” is everything. It’s the universe your code lives in — the Python version, the system libraries, and all the packages available to you. Getting this right is traditionally a nightmare of <em>Dockerfiles</em>, container registries, and version conflicts.</p><p>PyRun’s approach? A single, simple text file.</p><h3>The Easy Way: environment.yml</h3><p>For 90% of use cases, this is all you need. It’s a standard Conda environment file that lets you specify both Conda and Pip packages.</p><p>Let’s say your project needs <em>pandas</em>, <em>scikit-learn</em>, and the <em>Lithops</em> framework. Your <em>.pyrun/environment.yml</em> would look like this:</p><pre>name: base<br>channels:<br>  - conda-forge<br>dependencies:<br>  - python=3.12<br>  - pandas&gt;=1.5<br>  - matplotlib<br><br>  - pip:<br>    - scikit-learn==1.3.*<br>    - $LITHOPS # This is important for Lithops-based projects!</pre><p><strong>Here’s the magic:</strong> When you save this file, PyRun detects the change, and this will initiate a series of processes to build that image <strong>automatically and completely transparently </strong>for the user. Once completed, the next time you click “Run,” your cloud runs will automatically have the latest version of your runtime with the new libraries ready to run. You can view the build process in real time in the VSCode interface in the “Output” section or in the “Logs” section of the PyRun interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dZizlscSAVhbZRIG6ZyjOQ.png" /><figcaption>Build logs on PyRun</figcaption></figure><h3>The Power User Way: Dockerfile</h3><p>What if you need something more? A system-level dependency like a C++ compiler, a specific geospatial library, or full control over the base operating system? Just replace <em>environment.yml </em>with a <em>Dockerfile</em>.</p><p>For a project requiring the gdal geospatial library, your <em>.pyrun/Dockerfile</em> might look like this:</p><pre># Start from a base Python image<br>FROM public.ecr.aws/docker/library/python:3.12.0-slim-bookworm<br><br># Install system dependencies using apt-get<br>RUN apt-get update &amp;&amp; apt-get install -y --no-install-recommends \<br>    gdal-bin \<br>    libgdal-dev \<br>    &amp;&amp; rm -rf /var/lib/apt/lists/*<br><br># Install Python packages using pip<br>RUN pip install --no-cache-dir \<br>    rasterio \<br>    pandas<br># ... rest of your Dockerfile setup</pre><p>PyRun will automatically build this Docker image and use it as your runtime. This gives you ultimate flexibility.</p><p>No more<em> docker build</em>, no more <em>docker push</em>. You just declare what you need, and PyRun handles the rest. This gives you reproducible, powerful, and completely custom environments for every project.</p><h3>Step 2: From Zero to Results with Pipelines</h3><p>Now that you know how to build any environment, let’s see what you can do with them. <strong>Pipelines</strong> are PyRun’s killer feature for learning and discovery. They are complete, pre-configured projects that you can launch with a single click.</p><p>Instead of starting from a blank script, you can run a sophisticated, real-world application, see the results, and then explore its code and configuration to understand how it works.</p><h3>Real-World Use Cases in Action</h3><p>Here are a few of the powerful pipelines you can run on PyRun today.</p><h3>1. AI: Running Large Language Models (LLMs) with Ollama</h3><p>Want to experiment with models like Llama 3 or Mistral? The <strong>“LLM Execution with Ollama”</strong> pipeline provides an interactive notebook environment right inside your PyRun workspace. It lets you run and prompt LLMs locally within the workspace’s compute resources.</p><ul><li><strong>What it shows:</strong> How to set up an interactive AI environment.</li><li><strong>Concepts used:</strong> Custom runtime with the ollama library, interactive notebook execution.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p1Tfkwkkpwd3_r4cWx3ZFg.png" /><figcaption>LLM execution on PyRun</figcaption></figure><h3>2. AI: Image Classification with TensorFlow</h3><p>A classic but essential AI task. The <strong>“Image Classification”</strong> pipeline demonstrates a complete workflow:</p><ol><li>Loads a dataset of images (e.g., cats vs. dogs).</li><li>Builds and trains a Convolutional Neural Network (CNN) using TensorFlow/Keras.</li><li>Evaluates the model’s accuracy.</li></ol><ul><li><strong>What it shows:</strong> An end-to-end machine learning training workflow.</li><li><strong>Concepts used:</strong> Custom runtime with tensorflow and matplotlib, data loading, model training, and evaluation in the cloud.</li></ul><h3>3. Scientific Computing: Metabolite Annotation with METASPACE</h3><p>This is where PyRun’s power for scientific research shines. The <strong>“METASPACE Metabolite annotation pipeline”</strong> processes complex mass spectrometry imaging data (.imzML format). This task is computationally intensive and requires massive parallelism to analyze the molecular data against a large database.</p><ul><li><strong>What it shows:</strong> How PyRun handles highly specialized scientific data and computationally heavy, parallel workloads.</li><li><strong>Concepts used:</strong> Lithops for massive parallelism, custom runtime with specialized bioinformatics libraries, and handling of complex data formats.</li></ul><h3>4. Geospatial Showcase: Water Consumption Analysis</h3><p>The <strong>“Water consumption”</strong> pipeline is a fantastic example of a multi-step geospatial workflow. It estimates evapotranspiration by:</p><ol><li>Processing Digital Terrain Models (DTMs).</li><li>Interpolating meteorological data.</li><li>Running solar radiation models.</li></ol><p>This requires both parallelism (to process map tiles) and specific system-level tools.</p><ul><li><strong>What it shows:</strong> A complex, multi-stage scientific analysis that combines different data sources.</li><li><strong>Concepts used:</strong> A Dockerfile-based runtime to install libraries like <strong>GRASS GIS</strong>, and Lithops to parallelize the analysis across different geographical areas.</li></ul><h3>Your Turn to Build</h3><p>PyRun is more than just a cloud runner; it’s a complete ecosystem for building, deploying, and monitoring sophisticated Python applications. It handles the “how” (infrastructure, dependencies, scaling) so you can dedicate your brainpower to the “what” (your research, your models, your analysis).</p><p>Stop spending your days writing YAML and start solving real problems.</p><p><strong>Ready to build something amazing?</strong></p><ul><li><a href="https://app.pyrun.cloud/pipelines">Explore the Pipelines in PyRun</a></li><li><a href="https://docs.pyrun.cloud/">Read the Documentation</a> for deep dives into every feature.</li><li><a href="https://discord.gg/AF9XBqbxRS">Join our Discord Community</a> to share what you’re building</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a5878278ddf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Processing Cloud-optimized data in Python with Serverless Functions (Lithops, Dataplug)]]></title>
            <link>https://danielalecoll.medium.com/processing-cloud-optimized-data-in-python-with-serverless-functions-lithops-dataplug-c6e6f7fc8ff5?source=rss-1013236d8049------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6e6f7fc8ff5</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[cloud-optimized]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Daniel Alejandro Coll Tejeda]]></dc:creator>
            <pubDate>Mon, 31 Mar 2025 08:42:44 GMT</pubDate>
            <atom:updated>2025-03-31T08:42:44.133Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_gR8xHHWdyE9-Wh-J6gJ4Q.png" /><figcaption>Lithops x Dataplug.</figcaption></figure><p>You’ve got massive scientific datasets — terabytes of genomic sequences, geospatial imagery, or metabolomics scans — sitting in cloud object storage like AWS S3. You need to process it, analyze it, extract insights. But therein lies the headache: how do you efficiently feed this data into your compute jobs?</p><p>The traditional approaches often involve:</p><ol><li><strong>Downloading Everything:</strong> Slow, expensive, and requires massive local storage.</li><li><strong>Complex ETL Pipelines:</strong> Building and maintaining pipelines to transform data into analysis-ready formats can be brittle and time-consuming.</li><li><strong>Managing Big Data Clusters:</strong> Spinning up, configuring, and paying for clusters (like Spark, Dask, Ray on VMs) just to <em>access</em> the data adds significant overhead, even before the real work begins.</li></ol><p>What if you could process your data <em>directly</em> from object storage, using thousands of parallel workers, without moving the data or managing complex infrastructure?</p><p>Enter <strong>Cloud-Optimized (CO) data formats</strong> and <strong>Serverless Computing</strong>. CO formats (like Cloud-Optimized GeoTIFFs or Zarr) are designed for efficient partial reads from the cloud. Serverless platforms (like AWS Lambda or Google Cloud Functions) offer incredible elasticity, allowing you to spin up thousands of stateless functions on demand.</p><p>But there’s a catch: what about your <em>existing</em> data? Many widely used scientific formats (FASTA, FASTQ, VCF, imzML, LIDAR, even large CSVs) aren’t inherently cloud-optimized. Converting them is often a costly, one-off process that duplicates data.</p><p>This is where two powerful Python libraries come into play: <strong>Dataplug</strong> and <strong>Lithops</strong>.</p><ol><li><strong>Dataplug:</strong> Enables efficient, on-the-fly partitioning for <em>both</em> cloud-optimized and legacy data formats residing in object storage, <em>without</em> costly data duplication or rewriting.</li><li><strong>Lithops:</strong> A serverless data analytics platform that lets you run standard Python functions massively in parallel across the cloud with incredible ease and elasticity.</li></ol><p>In this post, we’ll explore how these tools work individually and how their combination unlocks a new level of efficiency and scalability for scientific data processing in the cloud.</p><h3>The Challenge: Data Gravity and Rigid Clusters</h3><p>Imagine a 10TB genomic dataset (FASTQ) or a massive LiDAR point cloud sitting in an S3 bucket.</p><ul><li><strong>Downloading is a no-go:</strong> It’s slow and requires massive local storage.</li><li><strong>Processing directly is tricky:</strong> How do you efficiently split a compressed FASTQ file or a complex LiDAR file into chunks that independent workers can process without downloading everything?</li><li><strong>Traditional Clusters (Spark, Dask, Ray):</strong> While powerful, they often require pre-provisioned resources. Scaling them up and down dynamically can be complex, and you pay for idle time. They might also struggle with direct, fine-grained access to object storage for non-CO formats.</li></ul><p>Object storage services like S3 are designed for high-bandwidth parallel reads using features like HTTP GET Byte-range requests. The key is to leverage this capability smartly.</p><h3>Dataplug: Your Universal Translator for Cloud Data</h3><p>Dataplug is a client-side Python library that tackles the partitioning problem head-on. Its core philosophy revolves around <strong>read-only, cloud-aware pre-processing</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*vLfvlEk86lTdkqUMj9aMhA.png" /><figcaption>Dataplug enables zero-cost re-partitioning via data slices.</figcaption></figure><p><strong>How it Works:</strong></p><ol><li><strong>Preprocessing (Once per Dataset):</strong> For a given dataset object (e.g., my_data.fasta in S3), you run co.preprocess(). Dataplug reads metadata and potentially builds small index files. Crucially, it <strong>doesn’t rewrite the original data</strong>. These indexes are stored separately (e.g., as another small object in S3). This step can be parallelized using backends like Dask or Ray via joblib.</li><li><strong>Partitioning (Zero-Cost):</strong> You then call co.partition(…) with a specific strategy (e.g., split into 8 chunks). Dataplug uses the pre-computed index to <strong>instantly</strong> generate a list of DataSlices.</li><li><strong>Data Slices:</strong> A DataSlice is <em>not</em> the data itself. It’s a lightweight, serializable Python object containing references (like byte ranges) telling a worker <em>how</em> to fetch a specific partition directly from the original object in S3.</li><li><strong>Lazy Evaluation:</strong> The actual data fetching (the HTTP GET requests) only happens when a worker calls the .get() method on a received DataSlice.</li></ol><p><strong>Key Advantages:</strong></p><ul><li><strong>Supports Legacy &amp; CO Formats:</strong> Works with CSV, text, FASTA, FASTQ(GZip), VCF, LiDAR, COPC, COG, imzML, and more. (Check <a href="https://github.com/CLOUDLAB-URV/dataplug">Dataplug Docs</a> for the full list and plugin details).</li><li><strong>Avoids Data Duplication:</strong> Keeps your original data untouched. Indexes are tiny compared to the raw data.</li><li><strong>Zero-Cost Re-partitioning:</strong> Generate different partitioning schemes (e.g., 8 chunks vs. 800 chunks) instantly from the same index.</li><li><strong>Framework Agnostic:</strong> Data Slices can be sent to workers managed by Dask, Ray, PySpark, or… Lithops!</li></ul><p><strong>Simple Dataplug Example (FASTA Processing):</strong></p><p>Let’s see how to prepare a FASTA file stored in S3 for parallel processing.</p><pre># Required installs<br>pip install dataplug[fasta] boto3 joblib</pre><pre>import math<br>from dataplug import CloudObject<br>from dataplug.formats.genomics.fasta import FASTA, partition_chunks_strategy<br>import logging<br><br># Configure logging for clarity<br>logging.basicConfig(level=logging.INFO)<br>logging.getLogger(&#39;dataplug&#39;).setLevel(logging.DEBUG) # Optional: More verbose Dataplug logs<br><br># --- Ensure AWS Credentials are Configured ---<br># Recommended: Use AWS CLI `aws configure` or IAM Roles.<br># Alternatively (less secure, for testing only):<br># import os<br># os.environ[&quot;AWS_ACCESS_KEY_ID&quot;] = &quot;YOUR_KEY&quot;<br># os.environ[&quot;AWS_SECRET_ACCESS_KEY&quot;] = &quot;YOUR_SECRET&quot;<br># --------------------------------------------<br><br># 1. Point Dataplug to your FASTA data in S3<br># Replace with your actual bucket and key<br>s3_path = &quot;s3://dnastack-covid-19-sra-data/PacBio/fasta/SRR16804994/SRR16804994.fasta&quot;<br>co = CloudObject.from_s3(FASTA, s3_path)<br>logging.info(f&quot;CloudObject created for: {s3_path}&quot;)<br><br># --- This only needs to be done ONCE per dataset ---<br># 2. Preprocess to create the index<br>#    Let&#39;s use 4 parallel threads locally via joblib<br>logging.info(f&quot;Starting preprocessing (file size: {co.size / (1024*1024):.2f} MB)...&quot;)<br>parallel_config = {&#39;backend&#39;: &#39;threading&#39;, &#39;n_jobs&#39;: 4, &quot;verbose&quot;: 10}<br># Calculate chunk size for 4 parallel preprocessing jobs<br>chunk_size = math.ceil(co.size / 4)<br>try:<br>    co.preprocess(parallel_config=parallel_config, chunk_size=chunk_size)<br>    logging.info(f&quot;Preprocessing completed for {s3_path}&quot;)<br>    logging.info(f&quot;FASTA file has {co.attributes.num_sequences} sequences.&quot;)<br>except Exception as e:<br>    logging.error(f&quot;Preprocessing failed: {e}&quot;)<br>    # If preprocessing failed, maybe the index already exists? Try loading metadata.<br>    try:<br>        co.load_metadata()<br>        logging.info(f&quot;Loaded existing metadata for {s3_path}&quot;)<br>        logging.info(f&quot;FASTA file has {co.attributes.num_sequences} sequences.&quot;)<br>    except Exception as load_exc:<br>        logging.error(f&quot;Failed to load existing metadata: {load_exc}&quot;)<br>        exit() # Can&#39;t proceed without metadata<br># ----------------------------------------------------<br><br># 3. Partition the data into slices (e.g., 8 chunks)<br>#    This step is FAST and uses the index. It returns lightweight slice objects.<br>num_chunks = 8<br>data_slices = co.partition(partition_chunks_strategy, num_chunks=num_chunks)<br>logging.info(f&quot;Created {len(data_slices)} data slices.&quot;)<br><br># 4. Demonstrate accessing a single slice (locally)<br>#    This is where the actual data fetching (HTTP GET ranges) happens<br>logging.info(&quot;Fetching content of the first slice locally...&quot;)<br>try:<br>    first_slice_content = data_slices[0].get()<br>    logging.info(f&quot; -&gt; First slice fetched, size: {len(first_slice_content)} bytes&quot;)<br>    # You could process `first_slice_content` here<br>except Exception as e:<br>    logging.error(f&quot;Error fetching first slice: {e}&quot;)</pre><p>This demonstrates Dataplug’s core workflow: point, preprocess (once), partition (cheaply). But how do we run processing on <em>all</em> slices in parallel across the cloud? That’s where Lithops comes in.</p><h3>Lithops: Serverless Supercomputing Made Simple</h3><p>Serverless compute platforms (like AWS Lambda) are extremely important for parallel tasks. You provide a function, and the cloud runs it, automatically handling scaling, deployment, and execution. You pay only for what you use, down to the millisecond. It scales elastically from zero to potentially thousands of concurrent executions.</p><p>However, using these platforms directly often involves complex deployment tools, managing dependencies, and handling communication. Lithops hides all that complexity behind a familiar Python Futures API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*bTOZ1tm-QIhWrTWpapX2dw.jpeg" /><figcaption>Lithops Architecture: Client interacting with Compute and Storage Backends.</figcaption></figure><p>With Lithops, you typically:</p><ol><li><strong>Write a Python function:</strong> This function takes some input and returns a result.</li><li><strong>Create a FunctionExecutor:</strong> Point it to your desired backend (AWS Lambda, Google Cloud Functions, Azure Functions, IBM Cloud Functions, Kubernetes, or even your localhost for testing).</li><li><strong>Call map or map_reduce:</strong> Pass your function and a list of data items. Lithops automatically:</li></ol><ul><li>Serializes your code and dependencies.</li><li>Deploys them to the serverless backend (if needed).</li><li>Invokes one function instance per data item (up to the backend’s concurrency limits).</li><li>Manages data movement (input arguments, return values) via object storage.</li><li>Monitors execution.</li></ul><p>4. <strong>Call get_result:</strong> Retrieve the results from all function invocations.</p><p><strong>A Simple Lithops Example (using localhost for easy testing):</strong></p><pre># Required installs<br>pip install lithops</pre><pre>import lithops<br>import logging<br><br>logging.basicConfig(level=logging.INFO)<br><br>def square(x):<br>    &quot;&quot;&quot;Simple function to square a number.&quot;&quot;&quot;<br>    logging.info(f&quot;Processing input: {x}&quot;)<br>    result = x * x<br>    logging.info(f&quot;Result for {x}: {result}&quot;)<br>    return result<br><br># Data to process<br>iterdata = [1, 2, 3, 4, 5, 6, 7, 8]<br><br>if __name__ == &#39;__main__&#39;:<br>    # Use Localhost backend (runs using local processes)<br>    # No cloud setup needed for this!<br>    fexec = lithops.LocalhostExecutor()<br>    logging.info(f&quot;Using executor: {type(fexec).__name__}&quot;)<br><br>    # Map the square function over the data<br>    # Lithops runs multiple &#39;square&#39; calls in parallel processes<br>    futures = fexec.map(square, iterdata)<br><br>    # Get the results (this waits for all functions to finish)<br>    logging.info(&quot;Waiting for results...&quot;)<br>    results = fexec.get_result(futures=futures)<br><br>    logging.info(&quot;\nFinal results:&quot;)<br>    print(results) # Output: [1, 4, 9, 16, 25, 36, 49, 64]</pre><p>This is simple, right? Now, imagine running this not with 8 local processes, but with 800 concurrent AWS Lambda functions, just by changing the executor and adding cloud configuration. That’s the power Lithops provides.</p><h3>The Power Couple: Dataplug Slices + Lithops Map</h3><p>Now, let’s combine them. Dataplug creates small, serializable DataSlice objects that represent chunks of our large FASTA dataset. Lithops can easily send these slices to serverless functions via its map method. Each function then calls .get() on its assigned slice to fetch only its portion of the data directly from S3 and process it.</p><p><strong>Combined Example: Processing FASTA Slices with Lithops</strong></p><pre># Required installs<br>pip install lithops dataplug[fasta] boto3 joblib</pre><pre>import math<br>from dataplug import CloudObject<br>from dataplug.formats.genomics.fasta import FASTA, partition_chunks_strategy<br>import lithops<br>import logging<br><br># Configure logging<br>logging.basicConfig(level=logging.INFO)<br># logging.getLogger(&#39;dataplug&#39;).setLevel(logging.DEBUG) # Optional: More Dataplug logs<br># Lithops logging can be configured via executor arguments or config file<br><br># --- Dataplug Setup (same as the Dataplug-only example) ---<br>s3_path = &quot;s3://dnastack-covid-19-sra-data/PacBio/fasta/SRR16804994/SRR16804994.fasta&quot;<br>co = CloudObject.from_s3(FASTA, s3_path)<br><br>try:<br>    # Try loading metadata first, preprocess if needed<br>    co.load_metadata()<br>    logging.info(f&quot;Loaded existing metadata for {s3_path}&quot;)<br>except Exception:<br>    logging.info(f&quot;Metadata not found, preprocessing {s3_path}...&quot;)<br>    parallel_config = {&#39;backend&#39;: &#39;threading&#39;, &#39;n_jobs&#39;: 4, &quot;verbose&quot;: 10}<br>    chunk_size = math.ceil(co.size / 4)<br>    co.preprocess(parallel_config=parallel_config, chunk_size=chunk_size)<br>    logging.info(f&quot;Preprocessing completed for {s3_path}&quot;)<br><br>logging.info(f&quot;FASTA file has {co.attributes.num_sequences} sequences.&quot;)<br><br>num_chunks = 8 # Partition into 8 slices for parallel processing<br>data_slices = co.partition(partition_chunks_strategy, num_chunks=num_chunks)<br>logging.info(f&quot;Created {len(data_slices)} data slices.&quot;)<br># -----------------------------------------<br><br># --- Lithops Function ---<br># This function runs in the cloud (e.g., AWS Lambda) or locally via LocalhostExecutor<br>def process_fasta_partition(data_slice, slice_id):<br>    &quot;&quot;&quot;<br>    Processes a single FASTA data slice fetched via Dataplug.<br>    Calculates basic stats for the sequences within the slice.<br>    &quot;&quot;&quot;<br>    # The data_slice object was sent by Lithops<br>    print(f&quot;Worker starting for slice {slice_id}&quot;) # Use print in workers for visibility<br>    try:<br>        # Fetch the actual data chunk from S3 via Dataplug&#39;s .get()<br>        fasta_content = data_slice.get().decode(&#39;utf-8&#39;)<br>        lines = fasta_content.split(&#39;\n&#39;)<br><br>        read_lengths = []<br>        sequence = &quot;&quot;<br>        processed_count = 0<br><br>        # --- Basic FASTA parsing logic ---<br>        for line in lines:<br>            if line.startswith(&#39;&gt;&#39;):<br>                if sequence: # Store length of the previous sequence<br>                    read_lengths.append(len(sequence))<br>                    sequence = &quot;&quot;<br>                    processed_count += 1<br>            else:<br>                sequence += line.strip() # Accumulate sequence lines<br><br>        if sequence: # Add the last sequence&#39;s length<br>            read_lengths.append(len(sequence))<br>            processed_count += 1<br>        # ----------------------------------<br><br>        if not read_lengths:<br>             # Handle empty slices or slices with no complete sequences<br>            min_len, max_len = None, None<br>        else:<br>            min_len = min(read_lengths)<br>            max_len = max(read_lengths)<br><br>        result_summary = {<br>            &#39;slice_id&#39;: slice_id,<br>            &#39;record_count&#39;: processed_count, # Number of sequences fully processed in this slice<br>            &#39;min_length&#39;: min_len,<br>            &#39;max_length&#39;: max_len,<br>            &#39;bytes_processed&#39;: len(fasta_content.encode(&#39;utf-8&#39;))<br>        }<br><br>        print(f&quot;Worker finished slice {slice_id}, records: {processed_count}, min: {min_len}, max: {max_len}&quot;)<br>        return result_summary<br>    except Exception as e:<br>        print(f&quot;Worker failed on slice {slice_id}: {e}&quot;)<br>        # Return error information for aggregation<br>        return {&#39;slice_id&#39;: slice_id, &#39;error&#39;: str(e)}<br># ----------------------<br><br>if __name__ == &#39;__main__&#39;:<br>    # --- Lithops Execution ---<br>    # Configure Lithops to use AWS Lambda and S3 (or another cloud/backend)<br>    # This typically involves setting up a config file (~/.lithops/config)<br>    # or passing a config dictionary.<br><br>    # &gt;&gt;&gt;&gt;&gt; CHANGE EXECUTOR HERE FOR CLOUD EXECUTION &lt;&lt;&lt;&lt;&lt;&lt;<br>    # fexec = lithops.ServerlessExecutor() # Example for AWS Lambda (requires config)<br>    fexec = lithops.LocalhostExecutor() # Using local processes for easy testing<br>    # -----------------------------------------------------<br>    logging.info(f&quot;Using executor: {type(fexec).__name__}&quot;)<br><br>    logging.info(f&quot;Mapping &#39;process_fasta_partition&#39; over {len(data_slices)} slices...&quot;)<br><br>    # Pass Dataplug&#39;s slices to Lithops map.<br>    # We add slice_id using enumerate for better tracking/logging in the worker.<br>    # Lithops serializes each (data_slice, i) tuple and sends it to a worker.<br>    map_iterdata = [(slice_obj, i) for i, slice_obj in enumerate(data_slices)]<br><br>    futures = fexec.map(process_fasta_partition, map_iterdata)<br><br>    # Wait for all parallel executions and get the results<br>    logging.info(&quot;Waiting for results...&quot;)<br>    results = fexec.get_result(futures=futures)<br><br>    logging.info(&quot;\n--- Processing Complete ---&quot;)<br>    successful_results = [r for r in results if &#39;error&#39; not in r]<br>    failed_results = [r for r in results if &#39;error&#39; in r]<br><br>    logging.info(f&quot;Successfully processed {len(successful_results)} slices.&quot;)<br>    if failed_results:<br>        logging.warning(f&quot;Failed to process {len(failed_results)} slices:&quot;)<br>        for failure in failed_results:<br>             logging.warning(f&quot;  Slice {failure[&#39;slice_id&#39;]}: {failure[&#39;error&#39;]}&quot;)<br><br>    # --- Aggregate Results ---<br>    total_records_processed = sum(r.get(&#39;record_count&#39;, 0) for r in successful_results)<br>    total_bytes_processed = sum(r.get(&#39;bytes_processed&#39;, 0) for r in successful_results)<br>    # Note: Min/Max aggregation requires filtering Nones if slices can be empty<br>    all_min_lengths = [r.get(&#39;min_length&#39;) for r in successful_results if r.get(&#39;min_length&#39;) is not None]<br>    all_max_lengths = [r.get(&#39;max_length&#39;) for r in successful_results if r.get(&#39;max_length&#39;) is not None]<br>    global_min_length = min(all_min_lengths) if all_min_lengths else None<br>    global_max_length = max(all_max_lengths) if all_max_lengths else None<br><br>    logging.info(f&quot;\n--- Aggregated Results ---&quot;)<br>    logging.info(f&quot;Total sequences processed across slices: {total_records_processed}&quot;)<br>    logging.info(f&quot;Overall minimum sequence length: {global_min_length}&quot;)<br>    logging.info(f&quot;Overall maximum sequence length: {global_max_length}&quot;)<br>    logging.info(f&quot;Total bytes processed: {total_bytes_processed / (1024*1024):.2f} MB&quot;)<br><br>    # Optional: Clean up Lithops temporary data (useful in cloud environments)<br>    # fexec.clean()<br>    logging.info(&quot;Done.&quot;)</pre><p><strong>Key Synergy Points:</strong></p><ol><li><strong>Dataplug prepares:</strong> Creates lightweight, parallel-friendly DataSlice objects from potentially huge, complex files in S3 <em>without</em> data duplication or costly conversion.</li><li><strong>Lithops distributes:</strong> Takes these slices and effortlessly distributes the process_fasta_partition function across potentially thousands of serverless functions.</li><li><strong>Workers fetch &amp; process:</strong> Each serverless function receives its slice, calls .get() to fetch <em>only its required data segment</em> directly from S3, and performs the computation.</li><li><strong>Lithops aggregates:</strong> Collects the results from all workers.</li></ol><p>This pattern allows you to achieve massive parallelism on your raw scientific data with minimal overhead and infrastructure management.</p><h3>Getting Started</h3><ol><li><strong>Install:</strong></li></ol><pre>pip install lithops <br>pip install &#39;dataplug[fasta]&#39; # Or other formats like [csv], [lidar], [cog]<br>pip install boto3 # For AWS S3<br>pip install joblib # Dataplug dependencie</pre><p>2. <strong>Configure Cloud Credentials:</strong> Ensure your environment has access to your cloud storage (e.g., AWS S3). Use aws configure, IAM roles, or environment variables.</p><p>3. <strong>Configure Lithops:</strong> For <em>cloud execution</em>, you’ll need to configure Lithops with your cloud provider details. Create a ~/.lithops/config file (or /etc/lithops/config, or set LITHOPS_CONFIG_FILE env var). See the <a href="https://lithops-cloud.github.io/docs/source/configuration.html">Lithops Configuration Docs</a> for details on setting up AWS, Google Cloud, Azure, IBM Cloud, etc. Start with the lithops.LocalhostExecutor() for easy local testing!</p><p>3. <strong>Try the Examples:</strong> Adapt the code snippets above with your S3 paths and data formats. Explore the <a href="https://github.com/CLOUDLAB-URV/dataplug/tree/master/examples">Dataplug examples</a> and <a href="https://github.com/lithops-cloud/lithops/tree/master/examples">Lithops examples</a>.</p><h3>Conclusion</h3><p>Stop wrestling with data movement and complex cluster setups. By combining Dataplug’s intelligent on-the-fly partitioning with Lithops’ seamless serverless execution, you can build powerful, elastic, and cost-effective data processing pipelines for your scientific workloads directly on cloud object storage.</p><p>This approach lets you focus on your scientific code, leveraging the scalability of the cloud without getting bogged down in infrastructure. Give Dataplug and Lithops a try and experience a simpler, more efficient way to process your large-scale scientific data in the cloud.</p><p><strong>Further Reading:</strong></p><ul><li><strong>Dataplug GitHub:</strong> <a href="https://www.google.com/url?sa=E&amp;q=https%3A%2F%2Fgithub.com%2FCLOUDLAB-URV%2Fdataplug">https://github.com/CLOUDLAB-URV/dataplug</a></li><li><strong>Lithops GitHub:</strong> <a href="https://www.google.com/url?sa=E&amp;q=https%3A%2F%2Fgithub.com%2Flithops-cloud%2Flithops">https://github.com/lithops-cloud/lithops</a></li><li><strong>Lithops Documentation:</strong> <a href="https://www.google.com/url?sa=E&amp;q=https%3A%2F%2Flithops-cloud.github.io%2Fdocs%2F">https://lithops-cloud.github.io/docs/</a></li><li><strong>Dataplug Example:</strong> <a href="https://github.com/ubenabdelkrim/PyRun-SciPy2025">https://github.com/ubenabdelkrim/PyRun-SciPy2025</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6e6f7fc8ff5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Supercharging Distributed Computing with Dask on IBM Code Engine]]></title>
            <link>https://danielalecoll.medium.com/supercharging-distributed-computing-with-dask-on-ibm-code-engine-0422e4577012?source=rss-1013236d8049------2</link>
            <guid isPermaLink="false">https://medium.com/p/0422e4577012</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[dask]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Daniel Alejandro Coll Tejeda]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 09:17:15 GMT</pubDate>
            <atom:updated>2024-09-24T09:17:15.572Z</atom:updated>
            <content:encoded><![CDATA[<p>Accelerating Dask workloads with IBM Code Engine, outperforming other managed Kubernetes cloud platforms with higher scalability and speed.</p><h4><strong>Introduction</strong></h4><p>In the world of big data and high computations, <strong>distributed computing has become the key of modern data science and analytics</strong>. An element of this revolution is Dask, a flexible library for parallel computing in Python. Dask has been a game-changer, allowing researchers and data scientists to scale their computations beyond the limits of a single-machine scheme.</p><p>But what if we could push Dask even further? What if we could harness the power of a cutting-edge cloud platform to supercharge our distributed workflows? That’s exactly what we’ve achieved with our <strong>new Dask backend for IBM Code Engine</strong>.</p><p>In this post, we’ll show you the development of this new backend, showing its capabilities and demonstrating how it outperforms existing solutions in the market.</p><h4>Cloud Platform Overview: Code Engine, Fargate &amp; Cloud Run</h4><p>A quick rundown of the three cloud platforms we considered for our Dask benchmarks:</p><p><a href="https://www.ibm.com/products/code-engine"><strong>IBM Code Engine</strong></a><strong>:</strong></p><p>A fully managed Kubernetes platform, Code Engine simplifies the deployment and management of Dask clusters without requiring in-depth Kubernetes knowledge. It offers several key advantages for Dask deployments:</p><ul><li><strong>Serverless Container Management:</strong> Code Engine eliminates the need for server management, allowing users and professionals to focus on deploying and scaling their Dask clusters.</li><li><strong>Direct Pod Communication:</strong> It allows the direct communication between the Dask scheduler and worker pods, eliminating intermediaries and ensuring efficient data exchange for optimal performance.</li><li><strong>Dynamic Scaling:</strong> This service has an auto-scaling system to adjust cluster resources based on workload demands, ensuring efficient resource utilization and cost optimization.</li></ul><p>The biggest drawback of this platform is the limitation on the number of jobs, CPU and memory that can be used in a single cluster. This limitation can be extended by contacting IBM support as we will see later.</p><p><a href="https://aws.amazon.com/fargate/"><strong>AWS Fargate</strong></a><strong>:</strong></p><p>AWS Fargate, a serverless compute engine for containers, offers a comparable solution to Code Engine on the AWS platform. Key features include:</p><ul><li><strong>Serverless Management: </strong>Fargate, like Code Engine, also allows you to focus on the code and let the platform manage the necessary resources.</li><li><strong>Kubernetes Integration:</strong> Also, this service integrates with Kubernetes, allowing you to deploy a Kubernetes pods to your Fargate cluster.</li><li><strong>Automatic Scaling and Resource Management:</strong> Similar to Code Engine, Fargate supports automatic scaling and granular resource control for Dask clusters.</li></ul><p>In this case we do not encounter a limitation as clear as with IBM Code Engine, but as we will see later, there is a bottleneck when launching a large number of machines.</p><p><a href="https://cloud.google.com/run"><strong>Google Cloud Run</strong></a><strong>:</strong></p><p>We initially considered GCP Cloud Run, however, after some testing, we encountered a significant limitation:</p><ul><li><strong>Lack of Direct Pod Communication:</strong> Unlike previous services, Cloud Run doesn’t allow pods to communicate directly with each other. It’s possible to enable communication between pods by adding an intermediary service like a Serverless VPC that acts as a connection channel. However, this approach would introduce additional delays and degrade performance.</li></ul><p>Given this limitation, we had to reject Cloud Run and continue with Code Engine and Fargate, as they both offer native direct communication, which is crucial for efficient Dask operations.</p><h4>Developing the Dask Backend for Code Engine</h4><p>Knowing fully well that IBM Code Engine offers a robust platform for distributed computing on managed Kubernetes infrastructure, we set out to implement a Dask backend with it, aiming to tap some great features Code Engine provides: direct pod-to-pod communication, high-speed scaling, and fine-grained resource control that improve Dask’s performance.</p><p>This development was closely aligned with the <a href="https://cloudprovider.dask.org/en/latest/"><strong>Dask Cloud Provider</strong></a><strong> </strong>project, ensuring smooth compatibility within the broader Dask ecosystem. We have developed the required Code Engine logic that deploys Dask clusters on the IBM platform along with proactive testing and validation.</p><p>The Code Engine backend has already been merged into the official Dask repository. IBM Code Engine integrates with the new major version of Dask, enabling improved scaling and efficiency for your distributed computing tasks.</p><h4>Dask Deployment on Code Engine</h4><p>With our Dask backend for Code Engine ready, let’s go over how you can easily create and manage your Dask clusters on this platform.</p><p><strong>Prerequisites:</strong></p><ul><li>An active IBM Cloud account with access to the Code Engine service.</li><li>Basic knowledge of Dask concepts.</li><li>Install the necessary packages: <a href="https://cloudprovider.dask.org/en/latest/installation.html"><strong>dask-cloudprovider</strong></a><strong> </strong>and<strong> </strong><a href="https://github.com/IBM/code-engine-python-sdk"><strong>ibm_code_engine_sdk</strong></a>.</li></ul><p><strong>Deployment Steps:</strong></p><ol><li><strong>Create a Code Engine Project</strong>: If you do not have a project yet, please log in to your IBM Cloud account and create one. This project will hold your Dask deployments. Then, retrieve your <a href="https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-project-id.html?context=wx"><strong>Project ID</strong></a>, which will allow Dask to create resources only within that specific project.</li><li><strong>Generate an IBM API key: </strong>Create an <a href="https://cloud.ibm.com/docs/account?topic=account-userapikey&amp;interface=ui&amp;locale=en#create_user_key"><strong>API key</strong></a> that enables communication between Dask and your IBM Code Engine project.</li><li><strong>Add Your API Key to Dask Configuration</strong>: You may either add the API key to your Dask configuration file or export it as an environment variable. Here is how you can do both:</li></ol><p><strong>Option 1: YAML Configuration</strong></p><pre># ~/.config/dask/cloudprovider.yaml<br>cloudprovider:<br>   ibm:<br>      api_key: &quot;your_api_key&quot;</pre><p><strong>Option 2: Environment Variable</strong></p><pre>export DASK_CLOUDPROVIDER__IBM__API_KEY=&quot;your_api_key&quot;</pre><p>You are ready now to deploy and execute your Dask pipeline. Here is the example:</p><pre>from dask_cloudprovider.ibm import IBMCodeEngineCluster<br>from dask.distributed import Client<br><br># Define cluster configuration<br>cluster = IBMCodeEngineCluster(<br>    project_id=&quot;your_project_id&quot;, <br>    region=&quot;your_region&quot;,<br>    scheduler_cpu=&quot;1&quot;, <br>    scheduler_mem=&quot;2G&quot;,<br>    worker_cpu=&quot;2&quot;, <br>    worker_mem=&quot;4G&quot;,<br>    worker_threads=2, <br>    n_workers=10 <br>)<br><br># Connect to the cluster<br>client = Client(cluster)<br><br># Submit your Dask computations here!<br># ...</pre><p><strong>Initial Limitations and Collaboration with IBM</strong></p><p>Initial testing revealed that <a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-limits#project_quotas">limitations</a> were present in the form of maximum CPUs and concurrent jobs. However, the team at <strong>IBM Code Engine was very responsive</strong> to our demands, increasing the limits and allowing to host larger workflows with a greater number of CPUs and jobs.</p><p>This step is necessary because IBM has a fairly tight limit on standard accounts, but to increase it you simply have to open a ticket and within a matter of hours the limit is increased.</p><h4>Code Engine vs. Fargate: A Detailed Comparison</h4><p>In order to accurately determine the true potential of our Dask backend for Code Engine, we have conducted a series of performance benchmarks, pitting it directly against AWS Fargate. Our goal was to evaluate both platforms across various workload scenarios, focusing on:</p><ul><li><strong>Scalability:</strong> How quickly and efficiently each platform can provision and utilize resources as the workload increases.</li><li><strong>Concurrency:</strong> The ability to execute multiple tasks simultaneously, maximizing resource utilization and minimizing overall execution time.</li><li><strong>Cluster Creation Time:</strong> The time each of the platforms took to provision and prepare the Dask cluster to be ready for computation.</li></ul><p>We designed two main experiments:</p><p><strong>Experiment 1: Sleep Test — Evaluating Scalability</strong></p><p>Here, we wanted to see the scaling and limits of concurrency for both backends. Accordingly, we submitted a map with 320 simple “sleep” jobs, designed to run for 60 seconds each, in two configurations:</p><ul><li><strong>Configuration A:</strong> 320 jobs with 1 CPU and 1 thread per job, in total 320 maps.</li><li><strong>Configuration B:</strong> 160 jobs with 2 CPUs and 2 threads per job, in total 320 maps.</li></ul><p>In this way, we would have a basis for comparison in performance while distributing the load on a larger number of smaller machines versus a smaller number of larger machines.</p><p><strong>Results:</strong></p><p>Code Engine consistently outperformed Fargate in both scenarios, demonstrating <strong>superior scalability and faster task execution</strong>. The plots below illustrate the differences in concurrency and execution time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*J24FLA22JlFKXP4uNiJwgQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*D_yMKfgGT9AdOcgVpxodFQ.png" /><figcaption>Execution of sleep with 1 thread/job on CE vs Fargate</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*xJPjDbckjxvg-KqhQyaJWw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*YZWsDXFsV187vqOcYhZ4VQ.png" /><figcaption>Execution of sleep with 2 threads/job on CE vs Fargate</figcaption></figure><p>As you can see, <strong>Code Engine achieved much higher concurrency</strong>, thus establishing its capability of quickly and efficiently launching and managing a large number of worker nodes. Fargate, on the other hand, exhibited a slower and more staggered scaling behavior, particularly when dealing with a high number of smaller machines.</p><p>To see this differences between the scalability and the resulting concurrency on both cases you can see on the below plots:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Wky0vZUBcD2fpc_HX410XQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*UpFpbmIr4dU-CTO1cjTDdA.png" /><figcaption>Job concurrency of Code Engine and Fargate with 1 thread/job and 2 threads/job</figcaption></figure><p>In this case, another again, you are able to notice a big difference, which is bigger when it is an experiment with a bigger number of small machines.</p><p><strong>Experiment 2: Monte Carlo Simulation for Pi</strong></p><p>To assess performance on a more challenging task with computational load, we setup a Monte Carlo simulation of estimating the value of Pi. We have run this simulation in the following two settings:</p><ul><li><strong>Configuration A:</strong> 100 jobs of 1 CPU per job, running 100 maps.</li><li><strong>Configuration B:</strong> 13 jobs of 8 CPUs per job, running 100 maps.</li></ul><p>This experiment aimed to analyze how both platforms handled a computationally heavier workload with varying resource allocations per job.</p><p><strong>Results:</strong></p><p>Results again showed Code Engine as the clear winner since, once again, <strong>cluster creation times and overall execution times are smaller in Code Engine</strong> compared to Fargate. The following plots illustrate these differences:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BL62LZlv6MTpkYzdYayvLg.png" /><figcaption>Time to create cluster with 8 CPUs/job and 1 CPU/job on CE vs. Fargate</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bHi8FJKsP8mpUYbzknopUw.png" /><figcaption>Time to execute Monte Carlo simulation with 8 CPUs/job and 1 CPU/job on CE vs. Fargate</figcaption></figure><p>Code Engine’s cluster creation time was significantly faster — 57 seconds vs. 102 seconds for Fargate — with bigger machines and less number of them, and the overall execution time of the Monte Carlo simulation was also much shorter — 11 seconds versus 46 seconds for Fargate with 1 CPU machines.</p><p><strong>Discussion</strong></p><p>Clearly from our benchmarking results, the <strong>performance benefits are much higher for the Dask backend of Code Engine compared to AWS Fargate</strong>. Because of its superior scalability, faster cluster creation times, and as a result, shorter execution times, Code Engine is a more favorable choice for running demanding Dask workloads in the cloud.</p><p>It is worth noting that Fargate’s performance appeared to degrade with increasing machine counts, perhaps showing some limits to its scalability, particularly when dealing with large machine counts. In contrast, in each of these scenarios, Code Engine consistently maintained high performance, demonstrating robustness and scalability.</p><p>It must be said that with executions of a smaller number of machines, but these being larger, the execution on Code Engine and Fargate are more similar than in executions with a larger number of machines, but these being smaller.</p><h4>Real-World Applications</h4><p>Using Dask on IBM Code Engine opens a window to a whole new world of possibilities when it comes to complex handling. Imagine being able to scale machine learning models to process terabytes of data, running large scientific simulations, or analyzing massive streams of real-time data without ever touching a single server.</p><p>Code Engine automatically moves resources to match the workload due to its serverless design — a great advantage if demands vary. This makes it economical because you only pay for what you use. Unpredictable workloads are especially a great fit for this, as this can be a very cost-effective solution.</p><h4>Conclusion</h4><p>In today’s fast-paced world of data-driven computing, finding solutions that are scalable, efficient, and cost-effective is becoming increasingly important. Through our development of a new Dask backend for IBM Code Engine, we aimed to explore how this platform can handle demanding distributed computing workloads.</p><p>Based on the benchmarks that we ran against AWS Fargate, Code Engine consistently outperformed it in key areas such as cluster creation time, scalability, and task execution. That is not to say that Fargate does not have its strong points — in the scenarios that we tested, and mostly those involving high concurrency and rapid scaling, Code Engine handled the workloads more fast and efficiently.</p><p>Our work shows that Code Engine is a good alternative for users who need managed Kubernetes for Dask without hassle with infrastructure complexity. Code Engine provides ease of use and may show superior performance in this distributed computing tasks.</p><p>This new Dask backend is developed by our team, and we are excited to see what other people will be able to do with those capabilities in their projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0422e4577012" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to run Lithops over EC2 VMs using the new K8s backend]]></title>
            <link>https://danielalecoll.medium.com/how-to-run-lithops-over-ec2-vms-using-the-new-k8s-backend-4b0a4377c4e9?source=rss-1013236d8049------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b0a4377c4e9</guid>
            <category><![CDATA[lithops]]></category>
            <category><![CDATA[parallel-computing]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Daniel Alejandro Coll Tejeda]]></dc:creator>
            <pubDate>Tue, 13 Feb 2024 18:30:13 GMT</pubDate>
            <atom:updated>2024-02-23T08:42:59.826Z</atom:updated>
            <content:encoded><![CDATA[<h4>Steps to Install and Configure a Kubernetes Backend on VMs with Lithops</h4><h3>Introduction</h3><p><a href="https://lithops-cloud.github.io/">Lithops</a> is a powerful framework that enables you to run your local Python code on the cloud without any modification or deployment hassle. You can use Lithops to scale up your data processing workloads and parallel applications across multiple cloud providers, such as <a href="https://cloud.ibm.com/login">IBM Cloud</a>, <a href="https://aws.amazon.com/">AWS</a>, <a href="https://azure.microsoft.com/">Azure</a>, <a href="https://cloud.google.com/">Google Cloud</a>, and <a href="https://kubernetes.io/">Kubernetes</a> or <a href="https://openwhisk.apache.org/">OpenWhisk</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*kThxv_mNbrB6FRJX1UXeaA.png" /><figcaption>Lithops logo.</figcaption></figure><p>Kubernetes, on the other hand, is a platform that facilitates the running and management of applications within a container-as-a-service (<a href="https://en.wikipedia.org/wiki/Content_as_a_service">CAAS</a>) infrastructure. It offers the flexibility to scale and update your applications easily across multiple virtual machines (VMs) with different resources.</p><p>In this guide, we will integrate these two powerful tools to develop and deploy multiple parallel and distributed applications on the cloud. We will use Lithops as a client that orchestrates the entire cloud architecture, enabling us to run it as conveniently and cost-effectively as possible.</p><p>We will explain how to launch a <a href="https://github.com/lithops-cloud/lithops/blob/master/docs/source/compute_config/kubernetes_rabbitmq.md">Lithops K8s backend</a> on a set of EC2 VMs to run in a fixed size Kubernetes cluster, which will enable us to execute serverless functions. This tutorial is structured into two main sections:</p><ul><li>Installation and configuration of multiple EC2 VMs to function and run as a Kubernetes cluster.</li><li>Installation and configuration of the Lithops client with our newly configured Kubernetes backend.</li></ul><h3>Kubernetes Cluster Using VMs</h3><p>There exists a multitude of methods to set up and initiate a Kubernetes backend tailored to various use-cases.</p><p>In our scenario, we will utilize multiple on-demand EC2 VMs, enabling us to create a Kubernetes cluster composed of several machines with diverse resources such as CPU, RAM, and storage. This approach provides us the flexibility to deploy a heterogeneous cluster.</p><p>This tutorial will guide you through the process of installing and configuring a Kubernetes cluster from scratch on a cluster of virtual machines.</p><h4>Kubernetes Nodes Specifications</h4><p>A Kubernetes cluster has two types of nodes:</p><ul><li><strong>Master Nodes</strong>: They control the pods, services, and other parts of the cluster. They use an API to communicate with the other nodes.</li><li><strong>Worker Nodes</strong>: They run the containers that make up the applications. These containers, called <strong>pods</strong>, have the application to run.</li></ul><p>To set up your Master and Worker nodes, you need the following minimum hardware:</p><ul><li>Memory: At least 2GB of RAM per machine.</li><li>CPUs: At least 2 CPUs on the Master node.</li><li>Internet Connection: You need to download the containers from the internet or a private registry.</li><li>Network Connection: All the machines in the cluster need to be able to talk to each other.</li></ul><h3>Steps to Install and Configure Kubernetes</h3><p>The following steps must be executed on all the machines in the cluster until the last steps, which will be mentioned on which side of the cluster they should be executed.</p><p>These steps have been carried out on VMs with 2 CPUs running Ubuntu version 22.04.</p><h4>Upgrade Your Ubuntu Servers</h4><p>To install the packages you need, you should first update your Ubuntu servers on the Master and Nodes:</p><pre>sudo apt update</pre><h4>Install Kubelet, Kubeadm and Kubectl</h4><p>To set up Kubernetes, you need to install three tools on your machines. These tools help you create and manage your cluster and run your code on it:</p><ul><li><strong>Kubeadm:</strong> This tool allows you to create a cluster and add more machines to it. You use this tool on the machine that will be the leader of the cluster, called the control plane.</li><li><strong>Kubectl: </strong>This tool allows you to interact with your cluster from the command line. You can use it to deploy your code, check the status of your cluster, and perform other tasks.</li><li><strong>Kubelet:</strong> This tool runs on each machine that will be part of the cluster, known as the worker nodes. It communicates with the control plane and starts new containers when needed.</li></ul><p>Install the necessary libraries:</p><pre>sudo apt-get update &amp;&amp; sudo apt-get install -y apt-transport-https curl</pre><p>Add the Kubernetes repository to install it:</p><pre>sudo mkdir -p /etc/apt/keyrings<br>echo &quot;deb [signed-by=/etc/apt/keyrings/kubernetes.gpg] https://apt.kubernetes.io/ kubernetes-xenial main&quot; | sudo tee /etc/apt/sources.list.d/kubernetes.list<br>curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes.gpg</pre><p>Now install the Kubernetes packages:</p><pre>sudo apt-get update<br>sudo apt-get install -y kubelet kubeadm kubectl</pre><p>With the following command we will keep the current version of these packages and avoid updates with the apt-get updatecommand. This process is recommended to avoid potential compatibility problems between versions.</p><pre>sudo apt-mark hold kubelet kubeadm kubectl</pre><h4>Verify the Installation</h4><pre>kubectl version --client</pre><p>Executing this command will yield an output similar to the following:</p><pre>Client Version: v1.28.2<br>Kustomize Version: v5.0.4–0.20230601165947–6ce0bf390ce3</pre><h4>Disable Swap</h4><p>Swap is a system that Linux uses to store temporary memory on the disk when the RAM is full. In this case, it is necessary to disable this system because the agent that runs Kubernetes on each node, Kubelet, needs to know the exact memory that each node has at all times in order to assign pods efficiently and avoid overloads.</p><pre>sudo swapoff -a<br>sudo sed -i.bak -r &#39;s/(.+ swap .+)/#\1/&#39; /etc/fstab<br>sudo mount -a</pre><p>Check that the configuration is correct, and the swap memory is not assigned:</p><pre>free -h</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Px0HpeMfbRJWuSqxzvGAYw.jpeg" /><figcaption>Expected output of the command.</figcaption></figure><h4>Load and Configure Linux Kernel Modules</h4><p>With this command, we will load the br_netfilter module of the Linux Kernel:</p><pre>sudo modprobe overlay<br>sudo modprobe br_netfilter</pre><p>Now, we need to configure the Kernel parameters for Kubernetes Networking:</p><pre>sudo tee /etc/sysctl.d/kubernetes.conf&lt;&lt;EOF<br>net.bridge.bridge-nf-call-ip6tables = 1<br>net.bridge.bridge-nf-call-iptables = 1<br>net.ipv4.ip_forward = 1<br>EOF</pre><p>And finally, we will apply this Kernel configuration changes:</p><pre>sudo sysctl --system</pre><h4>Install Container Runtime</h4><p>Deploying a Kubernetes cluster involves setting up a container runtime to execute containers within Pods. Kubernetes supports various container runtimes, and users can choose from the following options:</p><ul><li>Docker</li><li>CRI-O</li><li>Containerd</li></ul><p><strong>NOTE</strong>: You have to choose one runtime at a time.</p><p>We will use CRI-O, but you are free to choose another option.</p><h4>Install CRI-O Runtime</h4><p>First of all we will add the CRI-O repository to install it later. We will do it as the root user:</p><pre># Root user<br>sudo -i</pre><pre># Add the CRI-O repo<br>OS=&quot;xUbuntu_22.04&quot;<br>VERSION=1.26<br>echo &quot;deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /&quot; &gt; /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list<br>echo &quot;deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/ /&quot; &gt; /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.list<br>curl -L https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$VERSION/$OS/Release.key | apt-key add -<br>curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | apt-key add -</pre><p>After adding that, we need to install the following packages, we can do this step without root user:</p><pre>sudo apt update<br>sudo apt install cri-o cri-o-runc -y</pre><p>Start and check the status of the container runtime:</p><pre>sudo systemctl daemon-reload<br>sudo systemctl restart crio<br>sudo systemctl enable crio<br>systemctl status crio</pre><p>The output must be something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KDIDk69IPTDPz9_xgPxD5w.png" /><figcaption>Expected output of the CRI-O service.</figcaption></figure><h4>Init the Control Plane (MASTER NODE)</h4><p>After completing the preparation steps, it’s time to initialize the control plane node. This node will manage all workloads and handle communication between all worker nodes. <strong>This process is only on the Master node.</strong></p><pre>sudo systemctl enable kubelet</pre><p>In this step, depending on the container runtime chosen previously, you will have to execute one of these options:</p><pre># CRI-O <br>sudo kubeadm config images pull --cri-socket /var/run/crio/crio.sock<br># Containerd <br>sudo kubeadm config images pull --cri-socket /run/containerd/containerd.sock <br># Docker <br>sudo kubeadm config images pull --cri-socket /run/cri-dockerd.sock</pre><h4>Init the Kubernetes Cluster on the Master Node</h4><p>After all the installation, we will launch and initialize our Kubernetes cluster.</p><p>To do that, we will execute the next command:</p><pre>sudo kubeadm init --pod-network-cidr=10.244.0.0/16</pre><p>The --pod-network-cidr flag is used to specify the <a href="https://www.digitalocean.com/community/tutorials/understanding-ip-addresses-subnets-and-cidr-notation-for-networking">IP address range</a> for the Pods that will be deployed later. The default value of 10.244.0.0/16 is suitable for most situations, but you may need to adjust it if your network environment is very different.</p><p>It may take some time to create the cluster. You will see the progress on your terminal. When the cluster is ready, you should see this message:</p><pre>Your Kubernetes control-plane has initialized successfully!</pre><p>The output also includes the command with the token and ca-cert to add nodes to your Kubernetes cluster:</p><pre>kubeadm join 172.31.73.253:6443 --token 25wq8y.myynf8e3heeq2lly \<br> --discovery-token-ca-cert-hash sha256:22396afdf9654831e7a673153010afdb63469beb869ca0bcd95d8ca593c9912c</pre><p>You will need to do some other steps before adding your nodes to the Kubernetes cluster to ensure that it works as expected.</p><h4>Preparing your Kubeconfig File</h4><p>To start, copy the automatically generated Kubeconfig file into your personal .kube/config directory. After copying the file, be sure to adjust the ownership so that it is associated with your user account. This step is crucial as it enables Kubectl to properly read and interpret the file’s contents.</p><pre>mkdir -p $HOME/.kube<br>sudo cp -f /etc/kubernetes/admin.conf $HOME/.kube/config<br>sudo chown $(id -u):$(id -g) $HOME/.kube/config</pre><p>You can check the status of your cluster with this command:</p><pre>kubectl cluster-info</pre><p>If you want to run your Lithops client on your local machine you will need to copy the Kubernetes config to your machine.</p><h4>Installing a Pod Networking Addon on the Master Node</h4><p>To ensure the proper functioning of worker nodes in your Kubernetes cluster, it is essential to have a Pod networking addon installed. A <a href="https://kubernetes.io/docs/concepts/cluster-administration/addons/#networking-and-network-policy">compatible addon</a> must be manually installed to complete the installation process. While <a href="https://projectcalico.docs.tigera.io/about/about-calico">Calico</a> and <a href="https://github.com/flannel-io/flannel#deploying-flannel-manually">Flannel</a> are two popular choices, this guide opts for Calico.</p><p>Here are the steps to add Calico to your cluster using Kubectl:</p><pre>kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/tigera-operator.yaml<br>kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/custom-resources.yaml</pre><h4>Add Worker Nodes to our K8s Cluster</h4><p>To do this, we just need to copy the output of the previous command with all its parameters:</p><pre>sudo kubeadm join 172.31.73.253:6443 --token 25wq8y.myynf8e3heeq2lly \<br> --discovery-token-ca-cert-hash sha256:22396afdf9654831e7a673153010afdb63469beb869ca0bcd95d8ca593c9912c<br> --node-name custom-node-name</pre><p>You can use the --node-name flag to assign a custom name to the new node in the cluster.</p><p>If everything went well, you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y1qerStysORCVzfryKXF4Q.png" /><figcaption>Expected output of the previous command.</figcaption></figure><h3>Install and Configure Lithops</h3><p>Now that we have a Kubernetes cluster installed and configured to run, it’s time to smoothly install the Lithops client on your local machine. Let’s proceed with the next steps in this tutorial, ensuring a seamless transition to a powerful and efficient cloud computing experience.</p><p>In this case, a new alternative backend has been developed, leveraging the Kubernetes CAAS infrastructure to optimize and enhance the existing code. This enhancement aims to make the execution of pipelines, where launching hundreds of parallel tasks as quickly as possible is crucial, <a href="https://github.com/lithops-cloud/lithops/blob/master/docs/source/compute_config/kubernetes_rabbitmq.md">more rapid and efficient</a>. As evident from the provided link, the cold-start times and function parallelism have significantly improved.</p><p>In an upcoming article, we will present a comprehensive comparison between the two Kubernetes backends on Lithops. However, for this tutorial, we will utilize the Kubernetes work queue architecture, which is the most efficient and cost-effective for our virtual machine (VM) cluster.</p><h4>Setting up RabbitMQ for Lithops</h4><p>The initial phase in running and setting up Lithops involves the configuration of RabbitMQ. This service facilitates communication among the cluster’s workers and manages the distribution of tasks among them.</p><p>To leverage this new Kubernetes backend, we’ll utilize the advantages of RabbitMQ and its work queue architecture. Therefore, it’s essential to install and configure RabbitMQ properly.</p><p>The next steps is only required on the Client machine.</p><pre>sudo apt-get update -y<br>sudo apt-get install rabbitmq-server -y --fix-missing<br>sudo service rabbitmq-server start<br>sudo update-rc.d rabbitmq-server defaults<br>sudo rabbitmq-plugins enable rabbitmq_management<br>curl -i -u guest:guest http://localhost:15672/api/queues</pre><p>After successfully installing RabbitMQ and its associated packages, you can verify the installation by checking for the following output:</p><pre>HTTP/1.1 200 OK</pre><p>After receiving the successful output, we can proceed with configuring the AMQP URL for RabbitMQ. This step is crucial as it involves creating a user, defining a virtual host (vhost) on the Rabbit server, setting permissions for this user, and finally obtaining the AMQP URL necessary for utilizing the alternative backend in Lithops.</p><p>Follow these commands to configure the AMQP URL:</p><pre>sudo rabbitmqctl add_user user_name password<br>sudo rabbitmqctl add_vhost vhost_name<br>sudo rabbitmqctl set_permissions -p vhost_name user_name &quot;.*&quot; &quot;.*&quot; &quot;.*&quot;</pre><p>Change the previous commands with your user_name, password and vhost_name.</p><p>Finally, the AMQP URL will be something like this:</p><pre>amqp_url: amqp://user_name:password@IP_RabbitMQ_server:5672/vhost_name</pre><h4>Install Lithops Client</h4><p>With the successful installation and configuration of RabbitMQ, our next step is to install the Lithops client. Before installing, ensure that Python, Pip and Docker are already installed.</p><p>The installation and configuration process begins with the following command:</p><pre># If pip is not installed<br>sudo apt install python3-pip -y<br><br>pip install intall</pre><p>This command will install the latest version of Lithops that includes the new Kubernetes backend with some optimizations. This version is the <strong>3.1.2</strong>. Make sure to install this version or a more recent one. You can verify your current version using the following command:</p><pre>lithops --version</pre><h4>Setting up Lithops config file</h4><p>Once the installation is complete, you need to add the <a href="https://lithops-cloud.github.io/docs/source/configuration.html">Lithops configuration file</a>. In this file, specify the desired backend, in this case, <a href="https://lithops-cloud.github.io/docs/source/compute_config/kubernetes.html">K8s</a>, and one of the <a href="https://lithops-cloud.github.io/docs/source/storage_backends.html">available storage</a> options.</p><p>This file needs to be stored in your root directory of your project .lithops_config.</p><p>Your configuration file should look something like this:</p><pre>lithops:<br>   backend : k8s<br>   monitoring: rabbitmq<br><br>  rabbitmq:<br>    amqp_url: amqp://user_name:password@IP_RabbitMQ_server:5672/vhost_name<br><br>  k8s:<br>    ....<br>    docker_server       : docker.io<br>    docker_user         : &lt;Docker hub Username&gt;<br>    docker_password     : &lt;DOcker hub access TOEKN&gt;<br>    ....<br>    rabbitmq_executor : True</pre><p>In this configuration file, you have the flexibility to specify the granularity. Ideally, it should be a multiple of the number of functions and align with the number of CPUs on the nodes.</p><p>Granularity is controlled by the worker_processes parameter, which determines the number of CPUs per pod. This setting allows for pod granularity, where each pod can be configured to use a specific number of CPUs. By default, it uses all the CPUs of the nodes.</p><p><strong>Remember to include the </strong>rabbitmq_executor<strong> flag</strong>; without it, the old Kubernetes backend will be used instead.</p><p>As initially stated, setting up a <a href="https://lithops-cloud.github.io/docs/source/storage_backends.html">storage backend compatible</a> with Lithops is a prerequisite. However, the choice of storage backend is flexible, as it depends on your specific cloud service provider.</p><h4>Lithops custom runtime</h4><p>In scenarios where you need to use different libraries not included in the default runtime images, creating a custom runtime becomes essential. This enables the execution and import of specific libraries tailored to each backend.</p><p>In this example, we’ll illustrate the process of creating a <a href="https://github.com/lithops-cloud/lithops/tree/master/runtime">custom runtime</a> for execution on Kubernetes (K8s). These runtimes operate through Docker images, which include all the necessary packages and libraries. Keep in mind to install Docker if you want to build a Lithops custom runtime.</p><p>To get started, we’ll use the <a href="https://github.com/lithops-cloud/lithops/blob/master/runtime/kubernetes/Dockerfile">Dockerfile</a> corresponding to the K8s available in Lithops as a template. Once you’ve created and modified the relevant Dockerfile, use the following command to build and launch this custom image:</p><pre>lithops runtime build -f ./Dockerfile -b k8s your_account/lithops-rabbitmq:01</pre><h3>Running Lithops on K8s</h3><p>To test Lithops with our Kubernetes cluster, we’ll create a simple Python function that returns “Hello World!” of each node of the cluster.</p><p>Create a file named hello_world.py with the following content:</p><pre>import lithops<br><br>def my_map_function(x):<br> return &quot;Hello world!&quot;<br><br>if __name__ == &quot;__main__&quot;: <br> iterdata = list(range(0, 100))<br> fexec = lithops.FunctionExecutor(runtime=&quot;your_account/lithops-rabbitmq:01&quot;, backend=&quot;k8s&quot;)<br> <br> future = fexec.map(my_map_function, iterdata)<br> results = fexec.get_result()<br> print(&quot;Results: &quot; + str(results))<br> <br> fexec.clean()</pre><p>In this example, the iterdata variable is used to specify the number of functions you want to execute —in this case, 100 functions on our cluster. You can modify this variable to pass a list of parameters, a .csv file for analysis, or any other data relevant to your use case. This simplistic example ensures that everything is functioning as expected.</p><p>Make sure to replace the runtime parameter with the custom runtime you previously built.</p><p>If your output displays “Hello world!” a hundred times, you have successfully installed and configured your Kubernetes cluster with the Lithops client. This indicates that everything is set up correctly.</p><p>To verify that the Kubernetes pods are running, you can execute the following command:</p><pre>kubectl get pods</pre><p>You should observe output similar to the following:</p><pre>NAME                  READY   STATUS    RESTARTS   AGE<br>lithops-pod-node1–0   1/1     Running   0          5s<br>lithops-pod-node2–0   1/1     Running   0          5s<br>lithops-pod-node3–0   1/1     Running   0          5s<br>lithops-pod-node4–0   1/1     Running   0          4s<br>lithops-pod-node5–0   1/1     Running   0          4s</pre><h4>Running Lithops Benchmarks</h4><p>After successfully running the “Hello World” example and verifying that everything is functioning as expected, it’s time to run the Lithops-prepared benchmarks. These benchmarks allow you to assess the efficiency and potential of your Kubernetes cluster.</p><p>Firstly, you need to download the Lithops benchmarks and place them in your project’s folder. The benchmarks can be found <a href="https://github.com/lithops-cloud/applications/tree/master/benchmarks">here</a>.</p><p>The benchmarks and results obtained from running these benchmarks on multiple services such as AWS Lambda, S3, Google Cloud Run, etc., are accessible. You can use these as a reference to compare the performance of your cluster.</p><p>Upon downloading, you will find two directories: ./flops contains benchmarks to assess the potential of your compute backend, and ./object_storage to test the bandwidth of your storage backend.</p><p>To run this benchmarks you can use the following commands:</p><pre>python3.11 ./flops/flops_benchmark.py -b k8s -s aws_s3  --loopcount=15 --matn=4096 --tasks=100 --memory=1024 --outdir=plots/flops<br><br>python3.11 ./object_storage/os_benchmark.py run -b k8s -s aws_s3 --mb_per_file=512 --bucket_name=lithops-data --number=100 --outdir=plots/storage</pre><p>These commands will run the benchmarks on a Kubernetes (K8s) compute backend and an S3 storage backend. You can modify them to use your preferred storage backend. The various flags of the commands are explained within the flops_benchmark.pyand os_benchmark.py programs.</p><p>If executed successfully, you should see output similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*onAJbiIFLsmhP8O-" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*dFkVe8gyj9U88_E9" /><figcaption>Expected plots of the bechmarks.</figcaption></figure><p>These plots were generated using a cluster of 3 VM machines, each with 32 CPUs, and a supported Lithops storage. Please note that this is only an example output; actual results will vary based on the configurations of the different backends created following this guide.</p><h3>Conclusion</h3><p>This Medium post provides a comprehensive guide for anyone interested in creating, installing, and configuring a Kubernetes cluster composed of multiple VMs. All of these are conveniently managed by a Lithops client, which simplifies and streamlines the entire process for the user.</p><p>Thanks to this new architecture, you will be able to run and execute thousands of serverless functions and applications with ease, speed, and cost-effectiveness.</p><p>In future Medium posts, we will compare the previous Lithops K8s backend, which worked with a single Pod for each function, resulting in a more costly and less efficient process. We will contrast this with the new Kubernetes work queue architecture, which significantly enhances process efficiency.</p><p>Furthermore, we plan to publish a new article replicating this process using pre-configured Kubernetes services from AWS, Azure, or Google Cloud, such as <a href="https://aws.amazon.com/eks/">Amazon Elastic Kubernetes Service (EKS)</a>, <a href="https://azure.microsoft.com/en-us/products/kubernetes-service/">Azure Kubernetes Service (AKS)</a> or <a href="https://cloud.google.com/kubernetes-engine/">Google Kubernetes Engine (GKE)</a>. This will provide readers with a broader perspective and more options for implementing their Kubernetes clusters.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b0a4377c4e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>