R. Shneeman: "There's good use cases for threads in Ruby"

Ruby Hero 2016 talks about usage of threads in Ruby and his plans for a RailsClub talk
07 September 2017   1009

Richard Shneeman
Richard Shneeman

2016 Ruby Hero, top 50 Rails contributor.

On the eve of RailsClub 2017, on which Richard will be one of the speaks, we questioned him about his job and his views on Ruby development. 

Why you will talk about threads in Ruby?

A lot of people don’t use threads because it’s difficult. Inside of Ruby, there are many other complicated factors, like global variable, global virtual machine lock called the GVL. A lot of developers have misconception that threads are hard to use due to the fact that GVL make them slightly less useful. We can’t use them inside of Ruby. I’m trying to provide the arguments that there still is a very good usecases for threads in Ruby. Using threads is hard in any language, not only in Ruby. I had some experience with multi threads in C and it is so much harder than in Ruby. Ruby isn’t easiest language to use threads with, but not the hardest one. As app developers, we can see real performance benefits with threads. There is something you can do only with threads. For example, a background task. I have a library called "Puma Worker Killer". You can use it, for example, for every 4 hours recycle. You can't do it without threads. It uses threads as a basis of its work. So, i’ve decided to make a talk about threads.

Where do you use threads already?

Currently, I’m maintaining:

  • Puma Worker Killer
  • Threaded (a thread pool implementation)
  • Concurrent Ruby

Using threads, we can run checks in parallel and all checks are happening in the same time and it will run 6 times faster.  

How many threads can we start at the same time and how much memory it will take?

This is one of the hardest questions in the world! haha! I even asked an university professor about it and she couldn’t give me the good answer. In general, you can run as many processes as there are CPUs assuming your program was totally CPU bound and did not use any IO. So, figure out how many CPUs you have and run that number of processes.  Make sure you’re not going over your memory limits though. Threads are good at handling I/O, so the real question is how many threads per process to add.
Adding more threads per process will increase memory but also increase throughput. When the program is doing I/O like making a database call, it can switch to a new thread.
Alternative is to add even more processes. But they take even more memory than threads. Ruby takes a lot of memory already, so using only processes will take giant amount of memory. The number 1 reason for using threads is for memory sharing. The second reason is I/O. When there is an I/O, it’s really good candidate for using threads. Almost all Ruby and Rails apps use a ton of I/O so there is lots of room to add more threads for performance.  For a Rails server running on Puma a good number for of threads to start with is is 5. From there you can increase or decrease it. You want to maximize your throughput. If you add way too many threads, like hundreds then your application performance will be worse because there is lots of thread contention. You want to add threads until your throughput stops improving.
Telling exact number of threads is really hard, it depends on your exact application and the machine you are running on.

How have you become a programmer?

I started learning Ruby in my free time in the university. At that time, websites and webapps were very popular, everyone was talking about it. I heard about the success of Bill Gates and said “wow! I wanna be like him! Wanna make billion dollars!”. So I asked my roommate how to create a website, he was studying computer science. He said that one of the popular websites of that time uses Ruby on Rails. So I bought “Ruby on Rails for dummies” book. At university, I was studying for an engineer, to design refrigerators. It was kinda boring for me. So all my free time I was building websites. It was so much fun to me! I started to go to a developer meetups and user groups. So I became a professional programmer ever since.

What advice can you give for a newbie?

Try to find a thing that gonna make you a million dollars! haha! Sometimes people ask me “How to become a programmer, how to learn it?” I ask them to step back and figure out what is the thing they wanna build? Can you imagine it? It can be anything, but having a project in your head is very important. The hardest part of programming isn’t a technical aspect. The hardest is about getting and staying excited, being able to understand how things work. Find what makes you excited and stay with it!

What’s your hobby? How do you spend your free time?

Toolworking. I enjoy woodworking. But now I don't have free time, I go to school for master’s program. It takes a 100% of my free time. Also, in December I will have another hobby! My second child will be born. I'm excited about that! Kids are the full time job! I will have a two month work break and for that time everything else will be a hobby.

 

N. Sutterer: "Ruby is dead. Long live Ruby!"

Creator of Trailblazer that introduces several new abstraction layers into Rails, Rails contributor and gem author, speaker at Railsclub
15 January 2018   809

Nick Sutterer at RailsClub 2017
Nick Sutterer at RailsClub 2017

Hello! Please, introduce yourself in few words.

My name is Nick Sutterer, I’m developing software for like 22-25 years and I work like a consultant of my open source project for different companies. Sometimes I give presentations at conferences.

Is it your first time in Russia, Moscow, RailsClub?

It is. Everything for a first time. I’m blown away!

How do you like it?

Great! It’s amazing! Since I arrived, people care about me, people take me out, people show me the city, people give me history lessons. It’s amazing. Great food. We go to places and have a drink. I go to hotel, sleep, and everything starts again. That’s amazing! I’m really enjoying it.

Can you tell us about your report in few keynotes?

My talk was about the lack of innovation in Ruby language and about innovations that is happening in frameworks, that use Ruby. I’m just showing what we have. I try to inspire people and Ruby core team to pick some ideas from other technologies and make Ruby even better.

Your talk is called “Ruby is dead”. If Ruby is dead, what’s alive?

Ruby is dead. Long live Ruby. I’m trying to be provocative with my talk. I’m still coding Ruby everyday, I’m still traveling to all conference because I still believe that Ruby is an amazing programming language. There’s languages, showing up recently. Elixir or Golang for example. They have completely different way. They deal with problems and they are way more innovative. But they are brand new. I, actually, don’t think that Ruby is dead.

What you don’t like in Ruby the most?

I hate that we keep thinking in really old way. We reject innovation. It is especially due to frameworks like Rails. I would love to the more development of Rails, with all it’s huge audience. Ruby is lacking a lot of features that a lot of other languages have, like pattern matching and method overloading. The problem is that sometimes I feel that we are behind the innovations that happen to other languages. Specifically features, that make other languages amazing. We don’t have them, and it’s very sad.

What is your way to improve Ruby?

Every time is meet Matz at conference, I tell him for few hours what should be done to improve Ruby. Without any providing any help. It’s all about innovations. I try to innovate in my own framework, Trailblazer. So we can put the way we write business code to new level. I try to inspire people with my library code they use new concepts in Ruby that never been there before. I think that helping them to write the applications.

How do you see the world of programming in 10 and 50 years? And will Ruby and Rails have place in this future?

I don’t think Rails will have place. I really love Rails community and people in Rails Core. But I don’t think that Rails will be a thing in 10 years. But I think Ruby will still be around. It all depends on what is going to happen with Ruby 3.0. When it will be released and what features will it bring. I think Ruby will still be there. But I can’t tell you what will happen in 50 years. Because in 50 years there won’t be a need to program anymore. We will probably just write diagrams on the air.

In your opinion, what technologies are the most hypest today?

Craft beer and coffee, haha! Everything that hipsters do! Now everything is switching from OOP to FP. We are trying to avoid to have unwanted side effects in order to not let users to screw up internal state. Functional programming makes it impossible to users to do stuff in wrong order, for example. Like problems that we have in Ruby. I see a lot of development in functional languages because they are also way easy to paralyze and they have a lot of advanced features.

What advice can you give to average programmer to stand out the crowd?

Important thing in IT is that you always need to play with new tools. Even if you are not a super programmer, you have to look at the community and check what’s going on. It is really important to keep moving. Otherwise, I see that my current job at the police is really slow. They using very outdated technologies. A lot of people are affected. It is non productive. It’s good because a lot of people are keeping their jobs . But it is important to adopt new technologies. I’m not saying be a coding hipster and change your framework everyday. But a lot of new things in last 10 years make sense. People should use it and not just sit there and enjoy excellent job. They can get fired tomorrow.

What makes you excited about your job?

That’s beautiful question. I think that idea of open source is that you expose code that you think is helpful and people will tell you that it really is. This is what keeps me programming. When I write something and I see that a lot of people use it and they say like “It is so much better that I used before!” It’s great! This is making my day. It’s all about what comes back. I also program my own stuff and sometimes I think: “Yes!” But mostly I like when something what I do is helpful to other people.

Do you have any plans on writing a book?

I have already wrote one book. Two years ago, it took like 16 months. I was writing and inventing at the same time. That was a huge mistake! I was keeping updating my book with changes in my library code. It was massive. I plan to write more books, because it was fun. It has to be with the right timing. I’m not gonna write a book about, for example, a new version of my framework now because it’s still changing. I’m not gonna make this mistake again. It’s so much work! Unbelievable.

Do you have any nightmares, related to you job?

I used to have those kind of dreams few years ago. Sometimes I still have them.You always imagine software as something visual. Brain just does that. My dreams about those thing and passing the objects. And it’s always the wrong object! It’s the only nightmare that I have. I was able to have good work\life balance. So I have very rare the bad sleep. Even if I don’t look like it.