Setting up a proper monitoring overview over your application’s performance is a complex task. Normally, you’d first need to figure out what you need to monitor, then instrument your code, and finally make sense of all the data that has been emitted.

However, with a few things set in place, and an APM that natively supports Ruby, it’s easier than ever to take this step. In this post, we’ll show you how you can do it too.

Automatic Instrumentation — Handsfree APM Setup

To discover which pieces of your code are causing your performance issues, you’ll need to add instrumentation to it. …


This article has been modified from its original appearance in Playbook Thirty-nineA Guide to Shipping Interactive Web Apps with Minimal Tooling, and tailored to fit this guest post for AppSignal.

There’s a lot of functionality that your app needs to handle, but that logic doesn’t necessarily belong in the controller or even the model. Some examples include checking out with a cart, registering for the site, or starting a subscription.

You could include all this logic in the controller, but you’ll keep repeating yourself, calling the same logic in all those places. You could put the logic in…


In today’s post, we will look into Ruby’s #dup and #clone. We'll start with a real-life example that triggered this interest. After that, we'll dive deeper with the goal of learning how #dup is implemented in Ruby and how it compares to #clone. We'll then close of by implementing our own #dup method. Let's go!

When I worked at a company that specialized in setting up campaigns for NGO’s to collect donations, I regularly had to copy campaigns and create new ones. For example, after the 2018 campaign ended, a new one for 2019 was needed.

A campaign usually had…


Happy new year, and welcome back to Ruby Magic! In this winter episode, we’ll dive into bindings and scopes. So put on your skis and follow us deep into the woods.

Last time, we looked at closures in Ruby by comparing blocks, procs and lambdas. Aside from the differences between the three types, we touched on what defines a closure.

A closure is a first-class function with an environment. The environment is a mapping to the variables that existed when the closure was created. The closure retains its access to these variables, even if they’re defined in another scope.

We’ve…


Performance monitoring is an important part of running a successful application. One of the most basic ways to tell the performance of something is to measure the duration each time it happens and distill statistics from it.

Mean

The mean or average of a collection of values is a good start to see how good or bad something behaves. It is calculated by summing all the values under consideration and then dividing by the number of occurrences.

In Ruby, this is what calculating the mean response time would look like:

def mean(array) 
(array.sum.to_f / array.length).round(2)
end
durations = [1,2,3,4,5,6,7,8,9,0]
mean(durations) #=>…


Ruby has various ways of performing iteration — loops, blocks and enumerators. Most Ruby programmers are at least familiar with loops and blocks but Enumerator and Fiber often stay in the dark. In this edition of Ruby Magic, guest author Julik shines a light on Enumerable and Fiber to explain flow controlling enumerables and turning blocks inside out.

Suspending Blocks and Chained Iteration

We’ve discussed Enumerator in a previous edition of Ruby Magic, where we described how to return an Enumerator from your own #each method and what it can be used for. An even broader use case for Enumerator and Fiber is that they…


In this edition of Elixir Alchemy, we’ll dive into Elixir’s GenStage module. Along the way, we’ll explain backpressure and we’ll write a Genstage to query the blockchain. Let’s start by discussing how using a GenStage can solve buffering problems.

What Is a GenStage?

Imagine you’re consuming data from an external source. That source could be anything “streamable” — such as reading a file line-by-line, a table in a database, or even a sequence of requests to a 3rd party API.

In such scenarios, where you need to stream data into your system, and probably do some processing on each data point, it’s common to…


Threads and asynchronous environments are initially a bit tricky. Without a good mental model to organize interaction, it is easy to get into trouble and end up with unexpected results. On top of that, testing asynchronous code can be difficult without the right tools or test patterns.

Thinking about threads as people and shared objects as ‘things’ that can be owned helps to organize the working of a multithreaded system. In this episode we will go through an example to learn all about testing asynchronous Ruby code.

If you are using Rails or Rack or really any application that as…


In this edition of Ruby Magic, we’ll show you how to use code written in C from Ruby. This can be used to optimize performance sensitive parts of your code or to create an interface between a C library and Ruby. This is done by creating extensions that wrap libraries written in C.

There are a lot of mature and performant libraries written in C. Instead of reinventing the wheel by porting them we can also leverage these libraries from Ruby. In this way, we get to code in our favorite language, while using C libraries in areas where Ruby…


Gather ’round children, and let grandpa recount the ways of the old days when life was hard, and installing gems was a headache-inducing, hair-pulling, teeth-gritting ordeal.

Back when I was just starting in Ruby, there was no Bundler and gems had to be installed the hard way. In Rails, this meant running rake gems:install a million times, fixing occurring bugs along the way, until the command passed with no errors. Today, we’re going to create a gem the old school way, after looking into what gems are and how they work.

Gems, What Are They?

RubyGems are an easy way to extend your own code with functionality written by other people. For example, instead of writing your own authentication/authorization code, you can use Devise, or if you want to re-size…

AppSignal

Error tracking and performance insights for Ruby and Elixir without the silly per-host pricing. From Amsterdam with love.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store