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 ArticleActiveRecord 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 ArticleMongoid (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 ArticleExceptions 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 ArticleRuby 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 ArticleRuby 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 ArticleEmpty? 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 ArticleBenchmarking 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 ArticleRuby: 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 ArticleSidekiq 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 ArticleThe 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 ArticleThe 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 ArticleReduce 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 ArticleThe 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 ArticleFrom Sleep to Speed: Making Rdkafka Sync Operations 16 Times Faster
As an open-source developer, I constantly seek performance gains in the code I maintain. Since I took over rdkafka from AppSignal in November 2023, I promised not only to maintain the gem but to...
View ArticleUnder the Hood: Enhancing Karafka’s CPU and Memory Efficiency
Introduction Now and then, I like to go on a performance improvement hunt because life isn't just about adding new features. Recently, I have been focusing on enhancing efficiency, particularly...
View Article