Skip to main content

Get the Reddit app

Scan this QR code to download the app now
Or check it out in the app stores

Programming

anarchyCode
r/ProgrammerHumor

For anything funny related to programming and software development.


Members Online
anarchyCode
r/ProgrammerHumor - anarchyCode




So... what we all doing with our digital plushies? Mine went for a spin.
r/godot

The official subreddit for the Godot Engine. Meet your fellow game developers as well as engine contributors, stay up to date on Godot news, and share your projects and resources with each other. Maintained by the Godot Foundation, the non-profit taking good care of the Godot project - consider donating to https://fund.godotengine.org/ to keep us going!


Members Online
So... what we all doing with our digital plushies? Mine went for a spin.









120ms to 30ms: Python 🐍 to Rust 🦀🚀
r/rust

A place for all things related to the Rust programming language—an open-source systems language that emphasizes performance, reliability, and productivity.


Members Online
120ms to 30ms: Python 🐍 to Rust 🦀🚀

We love to see performance numbers. It is a core objective for us. We are excited at another milestone in our ongoing effort: a 4x reduction in write latency for our data pipeline, bringing it down from 120ms to 30ms! This improvement is the result of transitioning from a C library accessed through a Python application to a fully Rust-based implementation. This is a light intro on our architectural changes, the real-world results, and the impact on system performance and user experience.

Chart A and Chart B shown in the image above.

So Why did we Switch to Rust from Python? Our Data Pipeline is Used by All Services!

Our data pipeline is the backbone of our real-time communication platform. Our team is responsible for copying event data from all our APIs to all our internal systems and services. Data processing, event storage and indexing, connectivity status and lots more. Our primary goal is to ensure up-to-the-moment accuracy and reliability for real-time communication.

Before our migration, the old pipeline utilized a C library accessed through a Python service, which buffered and bundled data. This was really the critical aspect that was causing our latency. We desired optimization, and knew it was achievable. We explored a transition to Rust, as we’ve seen performance, memory safety, and concurrency capabilities benefit us before. It’s time to do it again!

We Value Highly Rust Advantages with Performance and Asynchronous IO

Rust is great in performance-intensive environments, especially when combined with asynchronous IO libraries like Tokio. Tokio supports a multithreaded, non-blocking runtime for writing asynchronous applications with the Rust programming language. The move to Rust allowed us to leverage these capabilities fully, enabling high throughput and low latency. All with compile-time memory and concurrency safety.

Memory and Concurrency Safety

Rust’s ownership model provides compile-time guarantees for memory and concurrency safety, which preempts the most common issues such as data races, memory leaks, and invalid memory access. This is advantageous for us. Going forward we can confidently manage the lifecycle of the codebase. Allowing a ruthless refactoring if needed later. And there’s always a “needed later” situation.

Technical Implementation of Architectural Changes and Service-to-Service and Messaging with MPSC and Tokio

The previous architecture relied on a service-to-service message-passing system that introduced considerable overhead and latency. A Python service utilized a C library for buffering and bundling data. And when messages were exchanged among multiple services, delays occurred, escalating the system's complexity. The buffering mechanism within the C library acted as a substantial bottleneck, resulting in an end-to-end latency of roughly 120 milliseconds. We thought this was optimal because our per-event latence average was at 40 microseconds. While this looks good from the old Python service perspective, downstream systems took a hit during unbundle time. This causes overall latency to be higher.

In Chart B above shows when we deployed that the average per-event latency increased to 100 microseconds from the original 40. This seems non-optimal. Chart B should show reduced latency, not an increase! Though when we step back to look at the reason, we can see how this happens. The good news is now that downstream services can consume events more quickly, one-by-one without needing to unbundle. The overall end-to-end latency had a chance to dramatically improve from 120ms to 30ms. The new Rust application can fire off events instantly and concurrently. This approach was not possible with Python as it would have also been a rewrite to use a different concurrency model. We could have probably rewritten in Python. And if it’s going to be a rewrite, might as well make the best rewrite we can with Rust!

Resource Reduction CPU and Memory: Our Python service would consume upwards of 60% of a core. The new Rust service consumes less than 5% across multiple cores. And the memory reduction was dramatic as well, with Rust operating at about 200MB vs Python’s GBs of RAM.

New Rust-based Architecture: The new architecture leverages Rust’s powerful concurrency mechanisms and asynchronous IO capabilities. Service-to-service message passing was replaced by utilizing multiple instances of Multi-Producer, Single-Consumer (MPSC) channels. Tokio is built for efficient asynchronous operations, which reduces blocking and increases throughput. Our data process was streamlined by eliminating the need for intermediary buffering stages, and opting instead for concurrency and parallelism. This improved performance and efficiency.

Example Rust App

The code isn’t a direct copy, it’s just a stand-in sample that mimics what our production code would be doing. Also, the code only shows one MPSC where our production system uses many channels.

  1. Cargo.toml: We need to include dependencies for Tokio and any other crate we might be using (like async-channel for events).

  2. Event definition: The Event type is used in the code but not defined as we have many types not shown in the this example.

  3. Event stream: event_stream is referenced but not created in the same way we do with many streams. Depends on your approach so the example keeps things simple.

The following is a Rust example with code and  Cargo.toml file. Event definitions and event stream initialization too.

Cargo.toml

[package]
name = "tokio_mpsc_example"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1", features = ["full"] }

main.rs

use tokio::sync::mpsc;
use tokio::task::spawn;
use tokio::time::{sleep, Duration};

// Define the Event type
#[derive(Debug)]
struct Event {
    id: u32,
    data: String,
}

// Function to handle each event
async fn handle_event(event: Event) {
    println!("Processing event: {:?}", event);
    // Simulate processing time
    sleep(Duration::from_millis(200)).await;
}

// Function to process data received by the receiver
async fn process_data(mut rx: mpsc::Receiver<Event>) {
    while let Some(event) = rx.recv().await {
        handle_event(event).await;
    }
}

#[tokio::main]
async fn main() {
    // Create the channel with a buffer size of 100
    let (tx, rx) = mpsc::channel(100);

    // Spawn a task to process the received data
    spawn(process_data(rx));

    // Simulate an event stream with dummy data for demonstration
    let event_stream = vec![
        Event { id: 1, data: "Event 1".to_string() },
        Event { id: 2, data: "Event 2".to_string() },
        Event { id: 3, data: "Event 3".to_string() },
    ];

    // Send events through the channel
    for event in event_stream {
        if tx.send(event).await.is_err() {
            eprintln!("Receiver dropped");
        }
    }
}

Rust Sample Files

  1. Cargo.toml:

    • Specifies the package name, version, and edition.

    • Includes the necessary tokio dependency with the “full” feature set.

  2. main.rs:

    • Defines an Event struct.

    • Implements the handle_event function to process each event.

    • Implements the process_data function to receive and process events from the channel.

    • Creates an event_stream with dummy data for demonstration purposes.

    • Uses the Tokio runtime to spawn a task for processing events and sends events through the channel in the main function.

Benchmark

Tools used for Testing

To validate our performance improvements, extensive benchmarks were conducted in development and staging environments. Tools, such as hyperfine https://github.com/sharkdp/hyperfine and criterion.rs  https://crates.io/crates/criterion  were used to gather latency and throughput metrics. Various scenarios were simulated to emulate production-like loads, including peak traffic periods and edge cases.

Production Validation

In order to assess the real-world performance of the production environment, continuous monitoring was implemented using Grafana and Prometheus. This setup allowed for the tracking of key metrics such as write latency, throughput, and resource utilization. Additionally, alerts and dashboards were configured to promptly identify any deviations or bottlenecks in the system's performance, ensuring that potential issues could be addressed promptly. We of course deploy carefully to a low percentage of traffic over several weeks. The charts you see are the full-deploy after our validation phase.

Benchmarks Are not Enough

Load testing proved improvements. Though yes, testing doesn’t prove success as much as it provides evidence. Write latency was consistently reduced from 120 milliseconds to 30 milliseconds. Response times were enhanced, and end-to-end data availability was accelerated. These advancements significantly improved overall performance and efficiency.

Before and After

Before the legacy system, service-to-service messaging was done with C library buffering. This involved multiple services in the message-passing loop, and the C library added latency through event buffering. The Python service added an extra layer of latency due to Python's Global Interpreter Lock (GIL) and its inherent operational overhead. These factors resulted in high end-to-end latency, complicated error handling and debugging processes, and limited scalability due to the bottlenecks introduced by event buffering and the Python GIL.

After implementing Rust, message-passing via direct channels eliminated intermediary services, while Tokio enabled non-blocking asynchronous IO, significantly boosting throughput. Rust's strict compile-time guarantees reduced runtime errors, and we get robust performance. Improvements observed included a reduction in end-to-end latency from 120ms to 30ms, enhanced scalability through efficient resource management, and improved error handling and debugging facilitated by Rust's strict typing and error handling model. It’s hard to argue using anything other than Rust.

Deployment and Operations

Minimal Operational Changes

The deployment underwent minimal modifications to accommodate the migration from Python to Rust. Same deployment and CI/CD. Configuration management continued to leverage existing tools such as Ansible and Terraform, facilitating seamless integration. This allowed us to see a smooth transition without disrupting the existing deployment process. This is a common approach. You want to change as little as possible during a migration. That way, if a problem occurs, we can isolate the footprint and find the problem sooner.

Monitoring and Maintenance

Our application is seamlessly integrated with the existing monitoring stack, comprising Prometheus and Grafana, enabling real-time metrics monitoring. Rust's memory safety features and reduced runtime errors have significantly decreased the maintenance overhead, resulting in a more stable and efficient application. It’s great to watch our build system work, and even better to catch the errors during development on our laptops allowing us to catch errors before we push commits that would cause builds to fail.

Practical Impact on User Experience

Improved Data AvailabilityQuicker write operations allow for near-instantaneous data readiness for reads and indexing, leading to user experience enhancements. These enhancements encompass reduced latency in data retrieval, enabling more efficient and responsive applications. Real-time analytics and insights are better too. This provides businesses with up-to-date information for informed decision-making. Furthermore, faster propagation of updates across all user interfaces ensures that users always have access to the most current data, enhancing collaboration and productivity within teams who use the APIs we offer. The latency is noticeable from an external perspective. Combining APIs can ensure now that data is available and sooner.

Increased System Scalability and Reliability

Rust-focused businesses will get a serious boost advantage. They'll be able to analyze larger amounts of data without their systems slowing down. This means you can keep up with the user load. And let's not forget the added bonus of a more resilient system with less downtime. We're running a business with a billion connected devices, where disruptions are a no-no and continuous operation is a must.

Future Plans and Innovations

Rust has proven to be successful in improving performance and scalability, and we are committed to expanding its utilization throughout our platform. We plan to extend Rust implementations to other performance-critical components, ensuring that the platform as a whole benefits from its advantages. As part of our ongoing commitment to innovation, we will continue to focus on performance tuning and architectural refinements in Rust, ensuring that it remains the optimal choice for mission-critical applications. Additionally, we will explore new asynchronous patterns and concurrency models in Rust, pushing the boundaries of what is possible with high-performance computing.

Technologies like Rust enhance our competitive edge. We get to remain the leader in our space. Our critical  infrastructure is Rusting in the best possible way. We are  ensuring that our real-time communication services remain the best in class.

The transition to Rust has not only reduced latency significantly but also laid a strong foundation for future enhancements in performance, scalability, and reliability. We deliver the best possible experience for our users.

Rust combined with our dedication to providing the best API service possible to billions of users. Our experiences positions us well to meet and exceed the demands of real-time communication now and into the future.





Reminder that the U.S. Department of Defense has published a beautiful guide on "Detecting Agile BS"
r/ExperiencedDevs

For experienced developers. This community should be specialized subreddit facilitating discussion amongst individuals who have gained some ground in the software engineering world. Any posts or comments that are made by inexperienced individuals (outside of the weekly Ask thread) should be reported. Anything not specifically related to development or career advice that is _specific_ to Experienced Developers belongs elsewhere. Try /r/work, /r/AskHR, /r/careerguidance, or /r/OfficePolitics.


Members Online
Reminder that the U.S. Department of Defense has published a beautiful guide on "Detecting Agile BS"

With all the hate that "[Aa]gile" is getting here once again, I wanted to remind everybody of this guide/questionnaire.

The purpose of this document is to provide guidance to DoD program executives and acquisition professionals on how to detect software projects that are really using agile development versus those that are simply waterfall or spiral development in agile clothing (“agile-scrum-fall”).

Each and every one of its criteria is to the point. If you can only answer the wrong answers for your organisation, IMO you have no business criticising [Aa]gile.

Criticise Scrum, SAFe and all those all you want, but your organization is most probably not agile.

DIB Guide: Detecting Agile BS



Working on smooth card behaviour for my game. Almost done!
r/godot

The official subreddit for the Godot Engine. Meet your fellow game developers as well as engine contributors, stay up to date on Godot news, and share your projects and resources with each other. Maintained by the Godot Foundation, the non-profit taking good care of the Godot project - consider donating to https://fund.godotengine.org/ to keep us going!


Members Online
Working on smooth card behaviour for my game. Almost done!

To anyone wondering if the "10 reviews" benchmark really matters that much, I can attest that it truly does!
r/IndieDev

This is the place for indie devs and gamers to share anything, be it game development, their favorite games or just cool images, GIFs and music from an indie game in a casual community-run environment. If you're an indie gamer, this place welcomes you too! After all, every gamer is a potential indie developer!


Members Online
To anyone wondering if the "10 reviews" benchmark really matters that much, I can attest that it truly does!
r/IndieDev - To anyone wondering if the "10 reviews" benchmark really matters that much, I can attest that it truly does!


You can kick enemies and watch 'em flop in our immersive sim game! What do you think overall about the ragdoll simulation?
r/IndieDev

This is the place for indie devs and gamers to share anything, be it game development, their favorite games or just cool images, GIFs and music from an indie game in a casual community-run environment. If you're an indie gamer, this place welcomes you too! After all, every gamer is a potential indie developer!


Members Online
You can kick enemies and watch 'em flop in our immersive sim game! What do you think overall about the ragdoll simulation?

Revanced can skip sponsors?!?!?!?
r/revancedapp

Continuing the legacy of Vanced


Members Online
Revanced can skip sponsors?!?!?!?

OK i just got a android phone and wanted to get rid of ads so i install revanced BUT I was watching a video about turning a ps2 into a linux machine (great vid btw) and me hearing it about to being a sponsord segment i was ready to skip through it BUT THEN IT JUST AUTOMATICALY DID IT?1?!?!?!??!!?1?!?!?!??!?! does anyone know if there is a pc equivlent adblocker that can do this BECAUSE WHERE HAS THIS BEEN ALL MY LIFE???

-ok thank you
-supersefernow

edit later - OMG THANK YOU SO MUCH FOR EVERONE SO RESPONDED THIS IS THE FIRST TIME I GOT KINDA VIRAL VERY LIKE 61 COMMENTS AS I'M TYPING AND 177 UPVOTES IS JUST INSANE TO ME anyways thank u so much you made my day : D



  • For anything funny related to programming and software development. members
  • A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design. members
  • A subreddit for all questions related to programming in any language. members
  • The subreddit covers various game development aspects, including programming, design, writing, art, game jams, postmortems, and marketing. It serves as a hub for game creators to discuss and share their insights, experiences, and expertise in the industry. members
  • Computer Programming members
  • Subreddit for posting questions and asking for general advice about your python code. members
  • A wholesome community made by & for software & tech folks in India. Have a doubt? Ask it out. members
  • For experienced developers. This community should be specialized subreddit facilitating discussion amongst individuals who have gained some ground in the software engineering world. Any posts or comments that are made by inexperienced individuals (outside of the weekly Ask thread) should be reported. Anything not specifically related to development or career advice that is _specific_ to Experienced Developers belongs elsewhere. Try /r/work, /r/AskHR, /r/careerguidance, or /r/OfficePolitics. members
  • The official subreddit for the Godot Engine. Meet your fellow game developers as well as engine contributors, stay up to date on Godot news, and share your projects and resources with each other. Maintained by the Godot Foundation, the non-profit taking good care of the Godot project - consider donating to https://fund.godotengine.org/ to keep us going! members
  • A community for discussing anything related to the React UI framework and its ecosystem. Join the Reactiflux Discord (reactiflux.com) for additional React discussion and help. members
  • A place for all things related to the Rust programming language—an open-source systems language that emphasizes performance, reliability, and productivity. members
  • Ask questions and post articles about the Go programming language and related tools, events etc. members
  • Discuss interview prep strategies and leetcode questions members
  • PowerShell is a cross-platform (Windows, Linux, and macOS) automation tool and configuration framework optimized for dealing with structured data (e.g. JSON, CSV, XML, etc.), REST APIs, and object models. PowerShell includes a command-line shell, object-oriented scripting language, and a set of tools for executing scripts/cmdlets and managing modules. members
  • The official Python community for Reddit! Stay up to date with the latest news, packages, and meta information relating to the Python programming language. --- If you have questions or are new to Python use r/LearnPython members
  • A subreddit for News, Help, Resources, and Conversation regarding Unity, The Game Engine. members
  • Next.js is a React framework for building full-stack web applications. members
  • .NET Community, if you are using C#, VB.NET, F#, or anything running with .NET... you are at the right place! members
  • All about the object-oriented programming language C#. members
  • Neovim is a hyperextensible Vim-based text editor. Learn more at neovim.io. members
  • Hello, IT. Have you tried turning it off and on again? members
  • members
  • [Docker](http://www.docker.io) is an open-source project to easily create lightweight, portable, self-sufficient containers from any application. The same container that a developer builds and tests on a laptop can run at scale, in production, on VMs, bare metal, OpenStack clusters, public clouds and more. members
  • members
  • Continuing the legacy of Vanced members
  • Discussions, articles and news about the C++ programming language or programming in C++. members
  • This subreddit has gone Restricted and reference-only as part of a mass protest against Reddit's recent API changes, which break third-party apps and moderation tools. For immediate help and problem solving, please join us at https://discourse.practicalzfs.com with the ZFS community as well. members
  • The goal of /r/SQL is to provide a place for interesting and informative SQL content and discussions. members
  • Bem-vindo à nossa comunidade! Todos os assuntos relacionados a TI, programação e afins são bem-vindos no r/brdev members
  • The place for news, articles and discussion regarding WordPress. members