Medellin, vibrant, beautiful, full of nature, mountains, joy and great food. I still miss the smell of good Colombian coffee, passion fruit juice and their typical dish, Bandeja Paisa. It is this city that since 2012 holds the title of the World's Most Entrepreneurial City and, because of this, has been selected to be the host of countless technology related events.
Medellin has been the setting for The Ruby Conference since 2015 and has had distinguished speakers with fascinating keynote speeches. This time was no exception, excellent and very interesting talks were shown on September 20th and 21st, 2019. Here are some of my favorites.
Cache is King, by Molly Struve
This extraordinary talk was about how to optimize our Ruby on Rails application using tools such as Redis and ElasticSearch along with simple techniques like adding indexes to tables or bulk processing.
Molly Struve described the way in which she drastically improved the performance of her company’s application by using this solution stack.
Bulk serialization is a technique that serves to stack calls to the database and execute them at once, this helps in greatly, but, strategically, she combined it with caching to be able to serialize from the cache instead of doing it directly from MySQL. In addition to that, the number of hits to Redis decreased 1000x when she only hashed the cache. That's wonderful optimization right there!
Another technique Struve used was the database fragmentation. With the Octopus gem you can configure Active Record to use multiple databases in a single Rails application, quite useful when high availability is needed.
If you want to dive further into this talk, you can find it here: https://speakerdeck.com/mstruve/cache-is-king-get-the-most-bang-for-your-buck-from-ruby.
High availability by offloading work: Background jobs, message queues or Kafka, by Kerstin Puschkeb
The optimization related keynotes are my favorites, Kerstin explained in a masterly way how to handle high availability using Background Jobs, messages oriented to middlewares, that despite having its ups and downs, it optimally manages the task routing shown to the user.
This keynote can be found at: https://speakerdeck.com/titanoboa/high-availability-by-offloading-work-background-jobs-message-queues-or-kafka
Going native with FFI, by Juan C. Ruiz
I had the opportunity to chat with Juan in one of the breaks and I found him to be a great person and a very humble and smart Ruby developer. Juan's keynote was spectacular. FFI stands for Foreign Function Interface, which is a mechanism used to make calls to routines written in another programming language.
In this case he was able to provide examples about creating a simple library in C and using it in Ruby. Perhaps there will be very few times in real life when you'll need this type of solution. However, it is a tremendous opportunity to experiment and learn more about how Ruby interacts with other languages. For example, how lower level functionalities can be written to be used in our applications.
The following keynote can be check out at: https://speakerdeck.com/juancrg90/going-native-with-ffi.
Rails optimization for humans, by Uriel Hernandez
I know Uriel's professional background from many years ago. In fact, Código Facilito was one of the first learning sources that I used to start in the Ruby on Rails world. His talk was quite captivating and accessible to developers at every experience level.
In short, he explained that every single web app needs to be optimized and it should accomplish these steps: Benchmarking; Server and Database optimization and Frontend optimization.
Benchmarking is a priority, this allows us to know the exact situation of your application. You must know exactly what to improve, in addition to comparing the progress before and after the improvements applied. Some measurement tools available are Rack::MiniProfiler and New Relic, both are quite easy to implement.
Server and database
The recommended optimizations are quite simple, between each version of Ruby and Ruby on Rails there are drastic improvements in performance. It is essential to stay updated. For instance, between Ruby 2.0.0 and 2.6.0 there is a 172% improvement in performance, this is greatly significant.
Regarding the optimizations of the database, there are also simple measures that can be applied, for example, the correct use of indexes. It is amazing how defining an index can improve performance in a query's response.
Another good practice is to count relations using count, instead of length, in addition to that, it is recommended to use counter caches and also to count on Selects.
You must be careful with N+1 queries, it is recommended to use include, preload or eager_load to avoid them. In addition you can use tools to detect them, the Bullet gem is one of the most recommended ones.
Our best tool to check out front-end performance is the browser's developer console, from here we can see the loading time of each file. You must optimize the images and compress the assets, among others.
Dive more into this keynote here: https://docs.google.com/presentation/d/1FSESDqx0WqiHeylPyFUheqiyLX6C2ar91Zw9urIu6G8/edit#slide=id.p.
The past, present and future of Rails at GitHub, by Eileen Uchitelle
I was truly fascinated by this talk, it perfectly describes what should and should not be done when building an application. Eileen works for GitHub and exposed all the challenges they faced when they updated to the latest Ruby on Rails version.
In 2009, GitHub developers decided “in a very smart way” to make a Rails fork to continue building the platform. While the versions of our favorite framework continued improving on and on, maintenance was more and more complicated at GitHub, besides other problems that had not been taken into account, for example, hiring.
In 2017 Eileen started to work on GitHub. Her mission? To migrate to Rails 4. However, when she attempted this migration, more than 4,000 errors popped up.
It was real madness! However, her hard work yielded rewards. Finally in mid-2018 GitHub updated to Rails 4.2 and now it runs the most recent versions.
This keynote can be checked out in: https://speakerdeck.com/eileencodes/ruby-on-ice-2019-the-past-present-and-future-of-rails-at-github.
Compacting GC for MRI, by Aaron Patterson
The last talk and "crown's jewel" was from Aaron Patterson. What Aaron has contributed to the Ruby community is invaluable, it is not trivial to say that he’s spent more than 10 years contributing to its core.
Aaron talked about one of the most important optimizations on memory allocation that Ruby has had, whole from his authorship. With his compression algorithm, it improves performance, prevents data fragmentation and optimizes direct memory access.
The slides of this talk can be checked at: https://speakerdeck.com/tenderlove/compacting-gc-in-mri-v2.
And well, my days went by between doing what I love the most, learning, and exploring a beautiful city, full of color and good food. On top of that, I shared time with amazing coworkers that I already miss and I hope we will meet again very soon.
It was an unforgettable experience and Medellin was just outstanding.