<?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 Agastyagaur on Medium]]></title>
        <description><![CDATA[Stories by Agastyagaur on Medium]]></description>
        <link>https://medium.com/@agastyagaur?source=rss-6d377c4bbb61------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EKJfeIat1dbYxVk4dJcrfw.jpeg</url>
            <title>Stories by Agastyagaur on Medium</title>
            <link>https://medium.com/@agastyagaur?source=rss-6d377c4bbb61------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 08:24:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@agastyagaur/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[Building a Parallel Merge Sort in C++: A One-Day Coding Journey]]></title>
            <link>https://medium.com/@agastyagaur/building-a-parallel-merge-sort-in-c-a-one-day-coding-journey-772b6d657cfc?source=rss-6d377c4bbb61------2</link>
            <guid isPermaLink="false">https://medium.com/p/772b6d657cfc</guid>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[parallel-computing]]></category>
            <category><![CDATA[dsa-problem]]></category>
            <dc:creator><![CDATA[Agastyagaur]]></dc:creator>
            <pubDate>Thu, 29 May 2025 05:38:21 GMT</pubDate>
            <atom:updated>2025-05-29T05:38:21.063Z</atom:updated>
            <content:encoded><![CDATA[<p>Over the past two days, I dove into a fascinating C++ project: implementing and comparing single-threaded and parallel merge sort algorithms. The goal was to explore how parallelism can boost performance and to understand the practical trade-offs of multi-threading in C++. Here’s a breakdown of what I built, what I learned, and how it all came together.</p><h3>Why Merge Sort and Parallelism?</h3><p>Merge sort is a classic divide-and-conquer algorithm, known for its stability and O(n log n) time complexity. But for large datasets, can we make it faster by leveraging modern multi-core CPUs? This question drove me to implement both a single-threaded MergeSort and a parallel PMergeSort using C++14 threads, then compare their performance on a 9,000-element array of random integers.</p><h3>What I Built 😊</h3><p>The project consists of a few key components:</p><ul><li><strong>Single-threaded MergeSort</strong>: A standard implementation that recursively splits an array, sorts subarrays, and merges them.</li><li><strong>Parallel PMergeSort</strong>: A multi-threaded version that spawns threads for subarray sorting, with a threshold (default: 5,000 elements) to switch to single-threaded sorting for smaller arrays to avoid thread overhead.</li><li><strong>Performance Tester</strong>: A main.cpp program that generates a 9,000-element array of random integers, runs both algorithms, and measures their execution times.</li><li><strong>Modular Structure</strong>: The code is organized into MergeSort.hpp/MergeSort.cpp for the single-threaded version and PMergeSort.hpp/PMergeSort.cpp for the parallel version.</li></ul><p>The setup is simple: compile with g++ -std=c++14 main.cpp MergeSort.cpp PMergeSort.cpp -o sort_program and run ./sort_program. The program outputs execution times for both algorithms, like:</p><pre>Time taken to sort (single thread): 0.01234 seconds<br>Time taken to sort (parallel): 0.00876 seconds</pre><h3>How It Works</h3><h3>Single-threaded Merge Sort</h3><p>The single-threaded version follows the classic merge sort approach:</p><ol><li><strong>Divide</strong>: Split the array into two halves until subarrays are small enough.</li><li><strong>Conquer</strong>: Sort each subarray recursively.</li><li><strong>Merge</strong>: Combine sorted subarrays into a single sorted array.</li></ol><p>This implementation is straightforward and serves as the baseline for comparison.</p><h3>Parallel Merge Sort</h3><p>The parallel version introduces multi-threading:</p><ul><li>For large subarrays (above the 5,000-element threshold), it spawns two threads to sort the left and right halves concurrently.</li><li>Below the threshold, it falls back to single-threaded merge sort to minimize thread creation overhead.</li><li>The merge step remains single-threaded, as parallelizing it added complexity without significant gains in my tests.</li></ul><p>The threshold is tunable in PMergeSort.cpp, allowing experimentation with different array sizes and system configurations.</p><h3>What I Learned</h3><p>Over these two days, I gained several insights:</p><ul><li><strong>Thread Management</strong>: Creating and joining threads in C++ using &lt;thread&gt; requires careful synchronization to avoid race conditions. I learned to use std::thread effectively and ensure threads complete before merging.</li><li><strong>Parallelism Trade-offs</strong>: Parallelism isn’t always faster. For small arrays, thread overhead outweighs the benefits, which is why the threshold is critical. My tests showed parallelism shining for larger arrays (e.g., 9,000 elements).</li><li><strong>Performance Tuning</strong>: Measuring execution time with std::chrono helped quantify the speedup. On my system, the parallel version was about 30% faster for 9,000 elements, but results vary by hardware and array size.</li><li><strong>Code Modularity</strong>: Splitting the project into separate header and source files for each algorithm made the codebase easier to maintain and extend.</li></ul><h3>Challenges and Solutions</h3><p>One challenge was determining the optimal threshold for switching to single-threaded sorting. I initially set it too low (1,000 elements), which led to excessive thread overhead. After experimenting, I settled on 5,000 elements, which balanced parallelism and overhead on my system.</p><p>Another hurdle was ensuring thread safety during array access. By carefully passing subarray ranges to threads and avoiding shared data during sorting, I prevented race conditions without needing locks, keeping the code efficient.</p><h3>Performance Insights</h3><p>The performance comparison was eye-opening. For a 9,000-element array, the parallel version consistently outperformed the single-threaded one, often by 20–30%. However, for smaller arrays (e.g., 1,000 elements), the single-threaded version was faster due to thread creation costs. This reinforced the importance of tuning parallelism for specific workloads.</p><h3>What’s Next?</h3><p>This project was a great way to deepen my understanding of C++ threading and algorithm optimization. Next, I’m considering:</p><ul><li>Experimenting with OpenMP for easier parallelism.</li><li>Testing on larger datasets or different hardware to explore scalability.</li><li>Adding visualization to show the sorting process in action.</li></ul><h3>Final Thoughts 💭</h3><p>Building this project in just two days was both challenging and rewarding. It showed me the power of parallel programming and the importance of understanding when and how to apply it. If you’re curious about C++ or parallel algorithms, I highly recommend trying a similar project — it’s a fantastic way to learn!</p><p>Feel free to share your thoughts or try the code yourself!</p><p>Link for code: https://github.com/Agastya18/multi-threaded-merge-sort-cpp</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=772b6d657cfc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Uptime in 2024: Using GitHub Actions to Set Up Cron Jobs and Keep Your Render Server…]]></title>
            <link>https://medium.com/@agastyagaur/mastering-uptime-in-2024-using-github-actions-to-set-up-cron-jobs-and-keep-your-render-server-17c434f20cd1?source=rss-6d377c4bbb61------2</link>
            <guid isPermaLink="false">https://medium.com/p/17c434f20cd1</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[latest]]></category>
            <category><![CDATA[render]]></category>
            <category><![CDATA[cronjob-scheduler]]></category>
            <dc:creator><![CDATA[Agastyagaur]]></dc:creator>
            <pubDate>Fri, 16 Aug 2024 05:59:33 GMT</pubDate>
            <atom:updated>2024-08-16T05:59:33.466Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mastering Uptime in 2024: Using GitHub Actions to Set Up Cron Jobs and Keep Your Render Server Running 24/7</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3d4qin-AGq6CGmcS7ZzrJw.jpeg" /></figure><h4><strong>Introduction:</strong></h4><p>In this article, I’ll guide you through the process of setting up a cron job using GitHub Actions to keep your Render server from spinning down during idle periods. This is particularly useful for applications that need to be available 24/7 but are hosted on platforms like Render that might spin down your server after a period of inactivity (15 min)🥲.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*rEO1ChkaUx25cFpa.gif" /></figure><h3>What Are Cron Jobs?</h3><p>A cron job is a command or script that is scheduled to run at fixed times, dates, or intervals. This makes it ideal for repetitive tasks like backups, maintenance scripts, or sending out periodic notifications.</p><h3><strong>Why Use GitHub Actions for the Cron Job?</strong></h3><p>GitHub Actions is a powerful tool that allows you to automate tasks directly from your GitHub repository. By using GitHub Actions, you can schedule a cron job that sends regular requests to your Render server, preventing it from spinning down.</p><h3>Setting Up the Cron Job:</h3><h4><strong>Step 1: Create a GitHub Action</strong></h4><p>First, navigate to your repository on GitHub. Create a new directory named .github/workflows if it doesn’t already exist. Inside this directory, create a new file called request-render.yml.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rEn8gDiodnRaKMjWXAHPRw.png" /><figcaption>img-1</figcaption></figure><h4><strong>Step 2: Define the Cron Schedule</strong></h4><p>In your request-render.yml file, add the following code:</p><pre># This will make a request render backend to stop spins down the server on idle<br>name: Request Render<br><br>on:<br>  workflow_dispatch:<br>  schedule:<br>    - cron: &quot;*/12 * * * *&quot;<br><br>jobs:<br>  request-render:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Request Render<br>        run: curl -X GET https://gambling-stake.onrender.com</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*99XOxWnX8JG-Ne8arW4iDw.png" /><figcaption>img-2</figcaption></figure><ul><li><strong>Explanation:</strong></li></ul><p>name: Request Render: This gives a name to the GitHub Action.</p><p>on: Specifies the events that trigger the action.</p><p>workflow_dispatch: Allows you to manually trigger the workflow.</p><p>schedule: Defines a cron schedule to run the workflow automatically. The cron expression */12 * * * * means the workflow will run every 12 minutes.</p><p>jobs: Specifies the jobs that the action will perform.</p><p>runs-on: ubuntu-latest: Defines the virtual environment to run the job. ubuntu-latest is a good default.</p><p>steps: The individual tasks within the job. Here, we use curl to make a GET request to the Render app URL.</p><p>Make sure to replace 👉 https://your-render-app.onrender.com with your actual Render app URL.</p><h4><strong>Step 3: Monitor and Deploy</strong></h4><p>Once the cron job is set up, it will automatically run every 12 minutes, keeping your Render server active. You can monitor the workflow runs in the “Actions” tab to ensure everything is functioning correctly.🥳</p><h3>Conclusion:</h3><p>By following this guide, you’ve successfully set up a cron job using GitHub Actions to prevent your Render server from spinning down during idle times. This ensures your application remains accessible without interruption.</p><p><em>If you enjoyed this article, please make sure to </em><a href="https://medium.com/@agastyagaur"><em>Subscribe</em></a><em>, Clap, Comment and </em><a href="http://www.linkedin.com/in/agastyagaur"><em>Connect with me </em></a><em>today! 🌐</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17c434f20cd1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a MERN Stack Application on a Unified Server: A Step-by-Step Guide to Cost-Free Hosting]]></title>
            <link>https://medium.com/@agastyagaur/deploying-a-mern-stack-application-on-a-unified-server-a-step-by-step-guide-to-cost-free-hosting-a9c2eb0e23a1?source=rss-6d377c4bbb61------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9c2eb0e23a1</guid>
            <category><![CDATA[mern-stack]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[render]]></category>
            <category><![CDATA[free-hosting]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Agastyagaur]]></dc:creator>
            <pubDate>Sun, 21 Jul 2024 06:21:32 GMT</pubDate>
            <atom:updated>2024-07-26T19:14:43.460Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jN5DIJWiq2hXoxxNAJDm7A.jpeg" /></figure><p><strong>Introduction:</strong></p><p>Deploying a MERN stack application (MongoDB, Express, React, Node.js) can seem daunting, but with the right steps, it becomes a smooth and straightforward process. This guide will walk you through deploying your MERN stack application with both frontend and backend served on the same port <strong>(Free on render) </strong>Let’s dive in!😎</p><h4><strong>Why Serve Both Frontend and Backend on the Same Port 🤔?</strong></h4><p>Before diving into the how-to, let’s explore why you might want to serve both your frontend and backend from the same port:</p><ul><li><strong>Simplified Deployment</strong>: Managing a single port for both frontend and backend can simplify your deployment process.</li><li><strong>Consistency</strong>: Avoid issues with CORS (Cross-Origin Resource Sharing) that can arise when your frontend and backend are served from different ports.</li><li><strong>Optimized Performance</strong>: Reduced complexity in handling client-server interactions can enhance overall performance.</li></ul><h3>Preparing Your App for Deployment</h3><blockquote><strong>I am assuming that your project directory may look like this👇 -</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IaiRYvCFrW2Htx7caAji7g.png" /><figcaption>pic- 1</figcaption></figure><ul><li><strong>To host both the frontend and backend of your MERN stack application on the same port, you can use the following approach (image 👇):</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w8usqKyb_o3vdSqCb9GDuA.png" /><figcaption>pic- 2</figcaption></figure><ol><li><strong>Combine Frontend and Backend</strong>: Build your React frontend into static files and serve them using your Express backend.</li><li><strong>Set Up Your Express Server</strong>: Configure your Express server to serve static files from your frontend build directory.</li></ol><h3>Step 1: go to the backend/server.js or index.js (pic- 1)</h3><ol><li>First, import the path: import path from &quot;path&quot;</li><li>Create the variable: const __dirname = path.resolve()</li><li>Now add 👇 code just below the API routes</li></ol><pre><br>if (process.env.NODE_ENV === &quot;production&quot;) {<br><br>// Serve static assets from the frontend build directory<br> app.use(express.static(path.join(__dirname, &quot;/frontend/dist&quot;)));<br><br>// Handle all other requests to serve the React app<br> app.get(&quot;*&quot;, (req, res) =&gt; {<br>  res.sendFile(path.resolve(__dirname, &quot;frontend&quot;, &quot;dist&quot;, &quot;index.html&quot;));<br> });<br>}</pre><ul><li>In <strong>step 1</strong> we configure our Express backend to serve our Frontend/React static files and handle API requests.</li><li><strong>Explanation: </strong>express.static serves the static files from the frontend/dist directory of your frontend build.</li><li>The app.get(&#39;*&#39;, ...) route sends the index.html file from the dist directory. for all other requests, enabling React Router to handle the routing.</li><li>The catch-all route is used path.resolve to ensure the path is correct regardless of the operating system.</li></ul><h3><strong>Step 3: Update </strong><strong>package.json (Root)</strong></h3><pre>&quot;scripts&quot;: {<br>  &quot;dev&quot;: &quot;NODE_ENV=development nodemon backend/server.js&quot;,<br>  &quot;start&quot;: &quot;NODE_ENV=production node backend/server.js&quot;,<br>  &quot;build&quot;: &quot;npm install &amp;&amp; npm install --prefix frontend &amp;&amp; npm run build --prefix frontend&quot;<br> },</pre><ul><li>Let’s break down the &quot;scripts&quot; section of your package.json file. These scripts define how to run and build your application, specifying commands for development, production, and building the frontend. Here’s a detailed explanation of each script:</li></ul><ol><li>Development Script: &quot;dev&quot;</li></ol><p><strong>Command Explanation</strong>:</p><ul><li>NODE_ENV=development: Sets the environment variable NODE_ENV to development. This is commonly used to enable development-specific features and debugging tools.</li><li>nodemon backend/server.js: Starts the server using nodemon, which automatically restarts the server when file changes are detected. This is useful during development to see changes without manually restarting the server.</li><li>npm run dev : will start the server in development mode, and nodemon will watch for changes in your backend/server.js file, restarting the server as needed.</li></ul><p>2. Production Script: &quot;start&quot;</p><p><strong>Command Explanation</strong>:</p><ul><li>NODE_ENV=production: Sets the environment variable NODE_ENV to production, optimizing the application for production use.</li><li>node backend/server.js: Starts the server using Node.js, running the backend/server.js script.</li><li>npm start : will start the server in production mode. Make sure you have your production dependencies installed and configurations set for a production environment.</li></ul><p>3. Build Script: &quot;build&quot; :</p><ul><li><strong>Command Explanation</strong>:</li><li>npm install: Installs all dependencies defined in your package.json file.</li><li>npm install --prefix frontend: Installs dependencies for the frontend located in the frontend directory.</li><li>npm run build --prefix frontend: Runs the build script in the frontend directory, which builds the React application.</li><li>npm run build : installs all necessary dependencies for both the backend and frontend, and then builds the React application, placing the build files in the frontend/build directory.</li></ul><h3>Step 4. Building the application</h3><ol><li>npm run build : installs all necessary dependencies for both the backend and frontend, and then build the React application, placing the build files in the frontend/build directory.</li><li>npm start : will start the server in production mode. Make sure you have your production dependencies installed and configurations set for a production environment.</li></ol><blockquote># <strong>“Now you will observe that your frontend is running on your backend port. To access it, simply navigate to backend url: </strong><a href="http://localhost:5000/"><strong>http://localhost:5000</strong></a><strong>.&quot;👊</strong></blockquote><h3>Step 5. Application Deployment on Render</h3><h4>1. Click on New.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c2jHXAJ2Fo-lolnZPIfDlA.png" /><figcaption>click on new.</figcaption></figure><h4>2. Click on Web Service.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qB-v7rqq0aFFx4GqIRiJbQ.png" /><figcaption>click on web service.</figcaption></figure><h4>3. Click on Connect.</h4><p>At this stage, you should connect the repository that you intend to deploy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fcdsBUC1LGW_PzPSoZ6Aqw.png" /><figcaption>connect your project.</figcaption></figure><h4>3. Add build &amp; start command.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ES90lS4BNczo_q7_YBr7kw.png" /><figcaption>build command=npm run build , start command=npm start</figcaption></figure><h4>4. Add Environment Variable and Deploy Web Service.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*itumBwHtjbLCZ2NCt5BvKA.png" /><figcaption>click deploy after adding .env</figcaption></figure><h3>Conclusion</h3><p>And that’s it! You’ve successfully deployed your MERN stack application with the frontend and backend served on the same port. This setup makes your app simple to manage and easy to scale.</p><p>Remember, the key steps are building the React app, configuring your Express server, updating package.json, and deploying to Heroku. If you have any questions or run into issues, feel free to ask. Happy coding and deploying😇!</p><p><strong>About the Author</strong></p><p>I’m dedicated to making technology accessible. Connect with me on [<a href="https://www.linkedin.com/in/agastyagaur">Linkedin</a>] to explore my work. Feel free to share your feedback and questions. Happy coding🥳!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9c2eb0e23a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>