Quantcast
Channel: Performance | Closer to Code
Browsing latest articles
Browse All 14 View Live

Image may be NSFW.
Clik here to view.

Using multiple MongoDB databases instead of one – performance check

I’m starting to develop a new application. Can’t say what it is, but it perfectly fits MongoDB Document Oriented Database approach. Everything is great. except of small detail – I don’t want to store...

View Article



ActiveRecord count vs length vs size and what will happen if you use it the...

One of the most common and most deadly errors you can make: using length instead of count. You can repeat this multiple times, but you will always find someone who’ll use it the way it shouldn’t be...

View Article

Mongoid (MongoDB) has_many/belongs_to relation and wrong index being picked

Sometimes when you have a belongs_to relations, you may notice, that getting an owner object can be really slow. Even if you add index like this: class Activity include Mongoid::Document include...

View Article

Image may be NSFW.
Clik here to view.

Exceptions should not be expected – stop using them for control flow (or any...

If your exceptions aren’t exceptions but expectations, you’re doing it wrong. Here’s an example what programmers tend to do: def validate_status(user) case user.status when 'active' then return user...

View Article

Image may be NSFW.
Clik here to view.

Ruby global method cache invalidation impact on a single and multithreaded...

Most of the programmers treat threads (even green threads in MRI) as a separate space, that they can use to simultaneously run some pieces of code. They also tend to assume, that there’s no “indirect”...

View Article


Image may be NSFW.
Clik here to view.

Ruby hash initializing – why do you think you have a hash, but you have an array

We all use hashes and it seems, that there’s nothing special about them. They are as dictionaries in Python, or any other similar structures available for multiple different languages. And that’s more...

View Article

Image may be NSFW.
Clik here to view.

Empty? vs blank? vs any? – why you should not use any? to test if there’s...

I often work with junior programmers and somehow they tend to use syntax like this: return unless array_data.any? # or do something if array_data.any? And there’s almost nothing wrong with it, as long...

View Article

Image may be NSFW.
Clik here to view.

Benchmarking Karafka – how does it handle multiple TCP connections

Recently I’ve released a Ruby Apache Kafka microframework, however I don’t expect anyone to use it without at least a bit information on what it can do. Here are some measurements that I took. How...

View Article


Image may be NSFW.
Clik here to view.

Ruby: Stream processing of shell command results

There are various methods for calling shell commands in Ruby. Most of them either not wait at all for the results, or wait until the command execution is finished. In many cases it is ok, because...

View Article


Image may be NSFW.
Clik here to view.

Sidekiq Unique Jobs: don’t waste your time waiting – reschedule if busy

Half a year ago, I’ve made a post about Enforcing unique jobs in Karafka and Sidekiq for single resources. This approach is great, however, there’s a particular case in which Sidekiq Unique Jobs can...

View Article

Image may be NSFW.
Clik here to view.

The hidden cost of the Ruby 2.7 dot-colon method reference usage

Note: This case is valid also for the “old” #method method usage. The reason why I mention that in the “dot-colon” context, is the fact that due to the syntax sugar addition, this style of coding will...

View Article

Image may be NSFW.
Clik here to view.

The hidden cost of a Ruby threads leakage

Bug hunting Recently I’ve been working with one small application that would gradually become slower and slower. While there were many reasons for it to happen, I found one of them interesting. To...

View Article

Image may be NSFW.
Clik here to view.

Reduce your method calls by 99.9% by replacing Thread#pass with Queue#pop

When doing multi-threaded work in Ruby, there are a couple of ways to control the execution flow within a given thread. In this article, I will be looking at Thread#pass and Queue#pop and how...

View Article


Image may be NSFW.
Clik here to view.

The Art of Forking: Unlocking Scalability in Ruby

Introduction The journey towards efficient parallelization in library development has often been based on using threads. As Karafka celebrates its eighth anniversary, it's become clear that while...

View Article
Browsing latest articles
Browse All 14 View Live




Latest Images