-4

I'm wondering if I should even consider to write a server-like program in Ruby (which will run for an infinite amount of time), since I'm worried about memory bloating.

I already have read this: Ruby Memory Management

However I'm still asking myself if it's a bad idea in general to do something in Ruby that is more than a little script.

For example, I have a [Ruby] program that is creating images with RMagick every few minutes and uploads them to a server. The only "trick" that I found is to work with forks (I have a 'looper' that will start a fork every few minutes which is doing all the actual work). Are there more elegant solutions to handle something like that in Ruby, or should I look for another language?

Community
  • 1
  • 1
Benedikt B
  • 733
  • 8
  • 23

1 Answers1

4

Ruby on Rails is written in Ruby. That answers your question if Ruby can be used for long-running servers or not.

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
  • 1
    HTTP-requests are not long-running. – Stefan Jul 29 '13 at 09:43
  • @Stefan HTTP servers are. HTTP-requests are not processes in the first place. – Lennart Regebro Jul 29 '13 at 09:52
  • Lennart, I thought about that, too. But I wasn't sure if the actual HTTP servers that run Rails are written in Ruby as well, or if those use "tricks" like forking to keep memory in line. – Benedikt B Jul 29 '13 at 11:23
  • I just looked into this, Nginx is written in C? Apache certainly not in Ruby – Benedikt B Jul 29 '13 at 11:28
  • @BenediktB: Your question was not about writing long running http servers, but about writing long running servers in general. Ruby on Rails is a long running server. Exactly how the HTTP server works depends on which HTTP server you have (you can use several different ones with RoR). Don't write your own HTTP server, it's difficult. – Lennart Regebro Jul 29 '13 at 11:46
  • Lennart, you brought up Rails/HTTP server. You said it would answer my question, however it does not. I'm not familiar with Rails and how it exactly works, but when looking into Rails it seems like usually there is some spawning mechanism behind it that will do the actual work. Do I understand that right, when running Rails there is no Ruby process that is running permanently and doing actual work? If so, doesn't this show what I explained in my question, and isn't Rails an invalid example then? – Benedikt B Jul 29 '13 at 13:11
  • @BenediktB: I brought up Rails. I did not bring up HTTP servers per se. There is a long running Ruby process with Rails, and if that's the HTTP server or not is besides the point. You do not run a new process per request as in PHP. http://stackoverflow.com/questions/1025432/is-rails-shared-nothing-or-can-separate-requests-access-the-same-runtime-variabl – Lennart Regebro Jul 29 '13 at 13:22
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34380/discussion-between-lennart-regebro-and-benedikt-b) as me saying the same thing over and over isn't of general interest. – Lennart Regebro Jul 29 '13 at 13:29