Category: Software

Ruby, Mongoid and (again) memory leaks – next Identity map problem

Lately I've fixed an issue with Mongoid driver (read more about this). Memory consumption stabilized at a relatively low level until... gem update mongo. Below you can see Munin memory and CPU consumption charts from a frontend server (frontend only presents data):

There were some heavy issues on october 23d. Server went really crazy. Behavior was similar to one mentioned in previous post about Mongoid. But IdentityMap has been turned off so WTF? Well I don't know what happend, but what do I know is how to fix it. Edit your Padrino/Sinatra app file (app/app.rb) and place this in your project class:

after do
  Mongoid::IdentityMap.clear
end

This will clear IdentityMap after each request.

I know, that this is not the best solution, however it is good enough for me - and what's more important - it works fine.

Using Savon Rb to communicate with SOAP client (http basic authentication and no WSDL file)

Most of the time, when we connect to webservices via SOAP (via SOAP! via SOAP! ;)), we have a WSDL file either local or downloaded from a server. But sometimes we need to connect to SOAP server which does not have this file and it is secured with http basic authentication.

To communicate with SOAP I use Savon Rb. It is easy and relatively fast. However in documentation there is nothing about communication with http basic authentication protected resources.

Although setting things up is really easy. First authentication:

@soap_client = Savon::Client.new do
  # Set basic authorization
  http.auth.basic "user_name", "password"
end

and non-wsdl connection:

@soap_client = Savon::Client.new do
  wsdl.endpoint = "http://service.example.com"
  wsdl.namespace = "http://v1.example.com"
end

and that's all. Now we can execute remote method like this:

@soap_client.request :get_items

or with params:

@last_response = @soap_client.request :get_items do
  soap.body = {
    :param_1 => "value_1",
    :param_2 => "value_2",
  }
end

Copyright © 2026 Closer to Code

Theme by Anders NorenUp ↑