Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory pilling up in publish #30

Closed
chenyujian opened this issue Oct 17, 2012 · 2 comments
Closed

memory pilling up in publish #30

chenyujian opened this issue Oct 17, 2012 · 2 comments

Comments

@chenyujian
Copy link

while(true){    
try{
        BasicMessage::ptr_t bm = BasicMessage::Create();
        bm->Body(message);
        m_channel->BasicPublish(exchangename, routingkey,bm,true, true);
        return true;
    }catch(MessageReturnedException& e){
        std::cout << e.what() << std::endl;
        return false;
    }
}

when setting "mandatory" bit true,and publishing msg that not routed,program will catch and print exception and memory is piliing up.i think it may be a bug when exception caught.

@alanxz
Copy link
Owner

alanxz commented Oct 17, 2012

I cannot reproduce the behavior you're describing with the following program:

#include <SimpleAmqpClient/SimpleAmqpClient.h>

#include <iostream>

using namespace AmqpClient;

int main()
{
  Channel::ptr_t channel = AmqpClient::Channel::Create();

  for (int i = 0; i < 1000000; ++i)
  {
    try
    {
      BasicMessage::ptr_t message = AmqpClient::BasicMessage::Create(std::string(1024*128, 'a'));
      channel->BasicPublish("", "noroute", message, true, true);
      return 0;
    }
    catch (MessageReturnedException &e)
    {
      std::cout << "Message delivery error: " << e.what() << std::endl;
    }
  }

  return 0;
}

That said rabbitmq-c, the library that SimpleAmqpClient wraps, has a limitation in the way it handles memory such that memory can only be released if all of the amqp_frame_t objects allocated since the last call to amqp_maybe_release_buffers() are no longer needed.

In your situation its likely SimpleAmqpClient has received other frames, probably from a consumer, from the broker while your code tries repeatedly to send the message, and thus cannot release memory.

There is a known issue that in certain pathological cases where you have two or more active consumers its possible that the library won't release any memory allocated until the AmqpClient::Channel object is destroyed. In the average case I don't this isn't an issue. A fix for this issue requires support from rabbitmq-c for finer grained memory control, which doesn't exist yet.

The workaround for this issue is to use multiple AmqpClient::Channel objects for each different consumer.

@alanxz alanxz closed this as completed Oct 17, 2012
@chenyujian
Copy link
Author

i review my code ,you are right, while consuming msg,i make a rpc request in one channel,so the memory is pilling up.

alanxz added a commit that referenced this issue Aug 15, 2013
Use new rabbitmq-c amqp_maybe_release_buffers_on_channel() API to
release memory on a per-channel basis.

Fixes #56
Fixes #30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants