You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by doublefox1981 <33...@qq.com> on 2009/04/14 16:18:43 UTC
c++ client , memory leak?
SubscriptionManager subscriptions(session);
Listener listener(subscriptions, session);
subscriptions.run()
because this block the thread, so i use subscriptions.get() in my mainloop, but i found the memory used by this process increase all the time, anybody happen this? help me. thanks
--
View this message in context: http://n2.nabble.com/c%2B%2B-client-%2C-memory-leak--tp2633382p2633382.html
Sent from the Apache Qpid developers mailing list archive at Nabble.com.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org
Re: c++ client , memory leak?
Posted by Gordon Sim <gs...@redhat.com>.
doublefox1981 wrote:
> int main(int argc, char** argv) {
> const char* host = argc>1 ? argv[1] : "192.168.1.233";
> int port = argc>2 ? atoi(argv[2]) : 5672;
> Connection connection;
> try {
> ConnectionSettings Setting;
> Setting.host = host;
> Setting.port = port;
> Setting.username = "uniqueeye";
> Setting.password = "uniqueeye";
> Setting.virtualhost = "/";
> Setting.maxFrameSize = 65535;
> Setting.mechanism = "PLAIN";
> connection.open(Setting);
> Session session = connection.newSession();
> //--------- Main body of program --------------------------------------------
>
> // Create a request queue for clients to use when making
> // requests.
> string request_queue = "request";
> // Use the name of the request queue as the routing key
> session.queueDeclare(arg::queue=request_queue);
> session.exchangeBind(arg::exchange="amq.direct", arg::queue=request_queue, arg::bindingKey=request_queue);
> // Create a listener and subscribe it to the request_queue
> std::cout << "Activating request queue listener for: " << request_queue << std::endl;
> SubscriptionManager subscriptions(session);
> Listener listener(subscriptions, session);
> subscriptions.subscribe(listener, request_queue);
Here you are setting up a subscription for message from request_queue
that will be dispatched to your listener, however you are never starting
the dispatching. Consequently incoming messages for this subscription
will simply queue up, never being processed.
If you don't want to dispatch messages to the listener (preferring to
pull messages off using SubscriptionManager::get()) you should remove
the two lines above from your code.
> // Deliver messages until the subscription is cancelled
> // by Listener::received()
> std::cout << "Waiting for requests" << std::endl;
> //subscriptions.run();
> Message Repuest;
> while (1)
> {
> bool HaveMessage = subscriptions.get(Repuest,request_queue,1*qpid::sys::TIME_MSEC);
> if(HaveMessage)
> {
> string routingKey;
> if (Repuest.getMessageProperties().hasReplyTo())
> {
> routingKey = Repuest.getMessageProperties().getReplyTo().getRoutingKey();
> }
> else
> {
> std::cout << "Error: " << "No routing key for request (" << Repuest.getData() << ")" << std::endl;
> }
> }
> // my other code
> Sleep(1);
> }
>
> //-----------------------------------------------------------------------------
> connection.close();
> return 0;
> } catch(const std::exception& error) {
> std::cout << error.what() << std::endl;
> }
> return 1;
> }
>
>
>
> this is my sample code, anything wrong with it?
>
> ------------------
> 何文辉
>
>
>
>
>
>
> ------------------ Original ------------------
> From: "Steve Huston (via Nabble)"<ml...@n2.nabble.com>;
> Date: 2009年4月14日(星期二) 晚上10:58
> To: "doublefox1981"<33...@qq.com>;
> Subject: RE: c++ client , memory leak?
>
>
>> SubscriptionManager subscriptions(session);
>> Listener listener(subscriptions, session);
>> subscriptions.run()
>>
>> because this block the thread, so i use subscriptions.get()
>> in my mainloop
>
> That is not necessary... Your MessageListener::received() method will
> be called when new messages arrive.
>
>> but i found the memory used by this process
>> increase all the time, anybody happen this? help me. Thanks
>
> What OS and qpid version is this?
> What data did you collect to detect the memory leak?
>
> -Steve
>
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project: http://qpid.apache.org
> Use/Interact: mailto:dev-subscribe@...
>
>
>
>
> This email is a reply to your post @ http://n2.nabble.com/c%2B%2B-client-%2C-memory-leak--tp2633382p2633614.html
> You can reply by email or by visting the link above.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org
Re:RE: c++ client , memory leak?
Posted by doublefox1981 <33...@qq.com>.
int main(int argc, char** argv) {
const char* host = argc>1 ? argv[1] : "192.168.1.233";
int port = argc>2 ? atoi(argv[2]) : 5672;
Connection connection;
try {
ConnectionSettings Setting;
Setting.host = host;
Setting.port = port;
Setting.username = "uniqueeye";
Setting.password = "uniqueeye";
Setting.virtualhost = "/";
Setting.maxFrameSize = 65535;
Setting.mechanism = "PLAIN";
connection.open(Setting);
Session session = connection.newSession();
//--------- Main body of program --------------------------------------------
// Create a request queue for clients to use when making
// requests.
string request_queue = "request";
// Use the name of the request queue as the routing key
session.queueDeclare(arg::queue=request_queue);
session.exchangeBind(arg::exchange="amq.direct", arg::queue=request_queue, arg::bindingKey=request_queue);
// Create a listener and subscribe it to the request_queue
std::cout << "Activating request queue listener for: " << request_queue << std::endl;
SubscriptionManager subscriptions(session);
Listener listener(subscriptions, session);
subscriptions.subscribe(listener, request_queue);
// Deliver messages until the subscription is cancelled
// by Listener::received()
std::cout << "Waiting for requests" << std::endl;
//subscriptions.run();
Message Repuest;
while (1)
{
bool HaveMessage = subscriptions.get(Repuest,request_queue,1*qpid::sys::TIME_MSEC);
if(HaveMessage)
{
string routingKey;
if (Repuest.getMessageProperties().hasReplyTo())
{
routingKey = Repuest.getMessageProperties().getReplyTo().getRoutingKey();
}
else
{
std::cout << "Error: " << "No routing key for request (" << Repuest.getData() << ")" << std::endl;
}
}
// my other code
Sleep(1);
}
//-----------------------------------------------------------------------------
connection.close();
return 0;
} catch(const std::exception& error) {
std::cout << error.what() << std::endl;
}
return 1;
}
this is my sample code, anything wrong with it?
------------------
何文辉
------------------ Original ------------------
From: "Steve Huston (via Nabble)"<ml...@n2.nabble.com>;
Date: 2009年4月14日(星期二) 晚上10:58
To: "doublefox1981"<33...@qq.com>;
Subject: RE: c++ client , memory leak?
> SubscriptionManager subscriptions(session);
> Listener listener(subscriptions, session);
> subscriptions.run()
>
> because this block the thread, so i use subscriptions.get()
> in my mainloop
That is not necessary... Your MessageListener::received() method will
be called when new messages arrive.
> but i found the memory used by this process
> increase all the time, anybody happen this? help me. Thanks
What OS and qpid version is this?
What data did you collect to detect the memory leak?
-Steve
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@...
This email is a reply to your post @ http://n2.nabble.com/c%2B%2B-client-%2C-memory-leak--tp2633382p2633614.html
You can reply by email or by visting the link above.
--
View this message in context: http://n2.nabble.com/c%2B%2B-client-%2C-memory-leak--tp2633382p2636274.html
Sent from the Apache Qpid developers mailing list archive at Nabble.com.
Re:RE: c++ client , memory leak?
Posted by doublefox1981 <33...@qq.com>.
i test if on windows and linux both.
i watch it the memory use increase to 700M after 10 hours,and i check the other code, it's all right.
------------------
何文辉
------------------ Original ------------------
From: "Steve Huston (via Nabble)"<ml...@n2.nabble.com>;
Date: 2009年4月14日(星期二) 晚上10:58
To: "doublefox1981"<33...@qq.com>;
Subject: RE: c++ client , memory leak?
> SubscriptionManager subscriptions(session);
> Listener listener(subscriptions, session);
> subscriptions.run()
>
> because this block the thread, so i use subscriptions.get()
> in my mainloop
That is not necessary... Your MessageListener::received() method will
be called when new messages arrive.
> but i found the memory used by this process
> increase all the time, anybody happen this? help me. Thanks
What OS and qpid version is this?
What data did you collect to detect the memory leak?
-Steve
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@...
This email is a reply to your post @ http://n2.nabble.com/c%2B%2B-client-%2C-memory-leak--tp2633382p2633614.html
You can reply by email or by visting the link above.
--
View this message in context: http://n2.nabble.com/c%2B%2B-client-%2C-memory-leak--tp2633382p2636263.html
Sent from the Apache Qpid developers mailing list archive at Nabble.com.
RE: c++ client , memory leak?
Posted by Steve Huston <sh...@riverace.com>.
> SubscriptionManager subscriptions(session);
> Listener listener(subscriptions, session);
> subscriptions.run()
>
> because this block the thread, so i use subscriptions.get()
> in my mainloop
That is not necessary... Your MessageListener::received() method will
be called when new messages arrive.
> but i found the memory used by this process
> increase all the time, anybody happen this? help me. Thanks
What OS and qpid version is this?
What data did you collect to detect the memory leak?
-Steve
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org