How to reduce the memory consumption of an HTTP:Server?

Hi everyone,

I’m trying to understand why an HTTP::Server consumes at least 400mb of memory.

Here is an example of an HTTP server that consumes 411mb of memory just by being started.

I would like to know if there is any way to reduce memory consumption because I have a project that starts several servers on the same server and this will cost me many gigabytes of memory.

Example:

require "http/server"

server = HTTP::Server.new do |context|
  context.response.content_type = "text/plain"
  context.response.print "Hello, World!"
end

address = "0.0.0.0"
port = 8080
puts "Listening on http://#{address}:#{port}"
server.bind_tcp(address, port)
server.listen

Memory usage:
image

Thanks.

I think this is the memory consumption of the compiler plus the executable, you could use crystal build and run the resulting binary instead

2 Likes

@HertzDevil

That was it!

Thanks, I’m not used to working with compiled languages.

Solved, just use crystal build

1 Like