You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by "fbarresi (via GitHub)" <gi...@apache.org> on 2026/04/20 15:43:15 UTC
[PR] Fix high CPU usage in case AmqpNetLite.Core 2.4.8+ [activemq-nms-amqp]
fbarresi opened a new pull request, #102:
URL: https://github.com/apache/activemq-nms-amqp/pull/102
Since AMQPNetLite [v2.4.8](https://github.com/Azure/amqpnetlite/releases/tag/v2.4.8) the IdleTimeOut supports negative values.
The new default value is -1.
If the timeout of -1 get casted to uint it becames uint.MaxValue.
This lead to wrong working heartbeat and **high CPU usage**.
Below a detailled explaination about the issue and how to reproduce it.
## How to reproduce the issue
This issue occurs every time you attempt to use a newer version of the AmqpNetLite.Core. The Nuget package for [ApacheNMS.AMQP](https://www.nuget.org/packages/Apache.NMS.AMQP#dependencies-body-tab) requires AMQPNetLite.Core >= 2.4.3 .
Up to version 2.4.7, there is no meaningful difference in the behavior of the library.
Starting on the version 2.4.8 and newer, I detected an high CPU consumption during idle.
This can be easily reproduced in this way:
1. Create an empty project and reference the AMQPNetLite.Core explicitly.
#### example.csproj
```
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AMQPNetLite.Core" Version="2.4.7" />
<PackageReference Include="Apache.NMS" Version="2.2.0" />
<PackageReference Include="Apache.NMS.AMQP" Version="2.4.0" />
</ItemGroup>
</Project>
```
#### Program.cs
```csharp
using Apache.NMS;
var connectionString = new Uri(Environment.GetEnvironmentVariable("ConnectionString")!);
var username = Environment.GetEnvironmentVariable("Username");
var password = Environment.GetEnvironmentVariable("Password");
var connection = new NMSConnectionFactory(connectionString, Array.Empty<object>())
.CreateConnection(username, password);
var session = connection.CreateSession();
connection.Start();
Console.WriteLine("Press enter to exit...");
Console.ReadLine();
```
2. Check the Performance differences between AMQPNetLite.Core 2.4.7 and 2.4.8.
- 2.4.7
Apart of some initial activity, you see 0% CPU usage
<img width="1352" height="350" alt="image" src="https://github.com/user-attachments/assets/1ff36f93-57a3-445f-8b5f-ad40c444d054" />
- 2.4.8
The CPU goes high up to 20% while the program is actually be in idle the whole time (no producers neither consumers)
<img width="1376" height="349" alt="image" src="https://github.com/user-attachments/assets/91691369-943c-4439-ba59-02368a652bdc" />
In a containerized application with low memory and CPU quota grant it go even higher.
## How/why this occurs
The apache.nsm.amqp library performs a casting from the default value (if not overriden):
<img width="824" height="359" alt="image" src="https://github.com/user-attachments/assets/14a7b3cd-9104-4a07-980d-5a6c34716e36" />
this lead to an unintended value in case of -1, the new default value fo this setting:
<img width="824" height="331" alt="image" src="https://github.com/user-attachments/assets/f5619de3-69f5-4e61-91c2-a9d90799fb3e" />
## Proposed solution
Since the underlaying library AmqpNetLite.Core changed the default value and its behavior in this matter, I think the apache.nsm.amqp should perfom a casting only if the IdleTimeOut is not negative and pass `0` elsewhere. This will allow to keep a low dependency requirement, remain backward capable and also fit newer version of AMQPNetLite.Core.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact
Re: [PR] Fix high CPU usage in case AmqpNetLite.Core 2.4.8+ [activemq-nms-amqp]
Posted by "davidvoit (via GitHub)" <gi...@apache.org>.
davidvoit commented on PR #102:
URL: https://github.com/apache/activemq-nms-amqp/pull/102#issuecomment-4486682725
Maybe this pull request can be combined with an upgrade to amqpnetlite 2.5.x? @Havret is this something which would make sense or is this something which should be a different pull request?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact
Re: [PR] Fix high CPU usage in case AmqpNetLite.Core 2.4.8+ [activemq-nms-amqp]
Posted by "Havret (via GitHub)" <gi...@apache.org>.
Havret commented on code in PR #102:
URL: https://github.com/apache/activemq-nms-amqp/pull/102#discussion_r3292489106
##########
src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs:
##########
@@ -115,7 +115,7 @@ internal void OnLocalOpen(Open open)
open.ChannelMax = Info.ChannelMax;
open.MaxFrameSize = (uint) Info.MaxFrameSize;
open.HostName = String.IsNullOrWhiteSpace(this.Provider.VHost) ? remoteUri.Host : this.Provider.VHost;
- open.IdleTimeOut = (uint) Info.IdleTimeOut;
+ open.IdleTimeOut = Info.IdleTimeOut > 0 ? (uint)Info.IdleTimeOut : 0;
Review Comment:
we definitely need a test for that
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact
Re: [PR] Fix high CPU usage in case AmqpNetLite.Core 2.4.8+ [activemq-nms-amqp]
Posted by "Havret (via GitHub)" <gi...@apache.org>.
Havret commented on code in PR #102:
URL: https://github.com/apache/activemq-nms-amqp/pull/102#discussion_r3291409515
##########
src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs:
##########
@@ -115,7 +115,7 @@ internal void OnLocalOpen(Open open)
open.ChannelMax = Info.ChannelMax;
open.MaxFrameSize = (uint) Info.MaxFrameSize;
open.HostName = String.IsNullOrWhiteSpace(this.Provider.VHost) ? remoteUri.Host : this.Provider.VHost;
- open.IdleTimeOut = (uint) Info.IdleTimeOut;
+ open.IdleTimeOut = Info.IdleTimeOut > 0 ? (uint)Info.IdleTimeOut : 0;
Review Comment:
Wouldn't it be better to not set it all here?
sth like:
```
if (Info.IdleTimeOut > 0)
{
open.IdleTimeOut = (uint)Info.IdleTimeOut;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact
Re: [PR] Fix high CPU usage in case AmqpNetLite.Core 2.4.8+ [activemq-nms-amqp]
Posted by "fbarresi (via GitHub)" <gi...@apache.org>.
fbarresi commented on code in PR #102:
URL: https://github.com/apache/activemq-nms-amqp/pull/102#discussion_r3293428901
##########
src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs:
##########
@@ -115,7 +115,7 @@ internal void OnLocalOpen(Open open)
open.ChannelMax = Info.ChannelMax;
open.MaxFrameSize = (uint) Info.MaxFrameSize;
open.HostName = String.IsNullOrWhiteSpace(this.Provider.VHost) ? remoteUri.Host : this.Provider.VHost;
- open.IdleTimeOut = (uint) Info.IdleTimeOut;
+ open.IdleTimeOut = Info.IdleTimeOut > 0 ? (uint)Info.IdleTimeOut : 0;
Review Comment:
solved - test added - s. updated PR
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact
Re: [PR] Fix high CPU usage in case AmqpNetLite.Core 2.4.8+ [activemq-nms-amqp]
Posted by "Havret (via GitHub)" <gi...@apache.org>.
Havret commented on code in PR #102:
URL: https://github.com/apache/activemq-nms-amqp/pull/102#discussion_r3292489106
##########
src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs:
##########
@@ -115,7 +115,7 @@ internal void OnLocalOpen(Open open)
open.ChannelMax = Info.ChannelMax;
open.MaxFrameSize = (uint) Info.MaxFrameSize;
open.HostName = String.IsNullOrWhiteSpace(this.Provider.VHost) ? remoteUri.Host : this.Provider.VHost;
- open.IdleTimeOut = (uint) Info.IdleTimeOut;
+ open.IdleTimeOut = Info.IdleTimeOut > 0 ? (uint)Info.IdleTimeOut : 0;
Review Comment:
@fbarresi we definitely need a test for that
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact
Re: [PR] Fix high CPU usage in case AmqpNetLite.Core 2.4.8+ [activemq-nms-amqp]
Posted by "Havret (via GitHub)" <gi...@apache.org>.
Havret commented on code in PR #102:
URL: https://github.com/apache/activemq-nms-amqp/pull/102#discussion_r3291409515
##########
src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs:
##########
@@ -115,7 +115,7 @@ internal void OnLocalOpen(Open open)
open.ChannelMax = Info.ChannelMax;
open.MaxFrameSize = (uint) Info.MaxFrameSize;
open.HostName = String.IsNullOrWhiteSpace(this.Provider.VHost) ? remoteUri.Host : this.Provider.VHost;
- open.IdleTimeOut = (uint) Info.IdleTimeOut;
+ open.IdleTimeOut = Info.IdleTimeOut > 0 ? (uint)Info.IdleTimeOut : 0;
Review Comment:
Wouldn't it be better to not set it here when it's default?
sth like:
```
if (Info.IdleTimeOut > 0)
{
open.IdleTimeOut = (uint)Info.IdleTimeOut;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact
Re: [PR] Fix high CPU usage in case AmqpNetLite.Core 2.4.8+ [activemq-nms-amqp]
Posted by "Havret (via GitHub)" <gi...@apache.org>.
Havret commented on PR #102:
URL: https://github.com/apache/activemq-nms-amqp/pull/102#issuecomment-4522987976
> Maybe this pull request can be combined with an upgrade to amqpnetlite 2.5.x? @Havret is this something which would make sense or is this something which should be a different pull request?
I think it would make better sense to bump amqpnetlite in a separate PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact
Re: [PR] Fix high CPU usage in case AmqpNetLite.Core 2.4.8+ [activemq-nms-amqp]
Posted by "fbarresi (via GitHub)" <gi...@apache.org>.
fbarresi commented on code in PR #102:
URL: https://github.com/apache/activemq-nms-amqp/pull/102#discussion_r3293428404
##########
src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs:
##########
@@ -115,7 +115,7 @@ internal void OnLocalOpen(Open open)
open.ChannelMax = Info.ChannelMax;
open.MaxFrameSize = (uint) Info.MaxFrameSize;
open.HostName = String.IsNullOrWhiteSpace(this.Provider.VHost) ? remoteUri.Host : this.Provider.VHost;
- open.IdleTimeOut = (uint) Info.IdleTimeOut;
+ open.IdleTimeOut = Info.IdleTimeOut > 0 ? (uint)Info.IdleTimeOut : 0;
Review Comment:
solved - s. updated PR
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact
Re: [PR] Fix high CPU usage in case AmqpNetLite.Core 2.4.8+ [activemq-nms-amqp]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #102:
URL: https://github.com/apache/activemq-nms-amqp/pull/102#discussion_r3291425371
##########
src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs:
##########
@@ -115,7 +115,7 @@ internal void OnLocalOpen(Open open)
open.ChannelMax = Info.ChannelMax;
open.MaxFrameSize = (uint) Info.MaxFrameSize;
open.HostName = String.IsNullOrWhiteSpace(this.Provider.VHost) ? remoteUri.Host : this.Provider.VHost;
- open.IdleTimeOut = (uint) Info.IdleTimeOut;
+ open.IdleTimeOut = Info.IdleTimeOut > 0 ? (uint)Info.IdleTimeOut : 0;
Review Comment:
Consider adding a regression test around OnLocalOpen / idle-timeout negotiation to cover the cases that triggered this bug (e.g., Info.IdleTimeOut = -1 should result in open.IdleTimeOut = 0, and a positive value should be preserved). The repo already has unit tests for other AMQP provider components, but this edge case currently isn’t exercised and could regress silently.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact
Re: [PR] Fix high CPU usage in case AmqpNetLite.Core 2.4.8+ [activemq-nms-amqp]
Posted by "fbarresi (via GitHub)" <gi...@apache.org>.
fbarresi commented on PR #102:
URL: https://github.com/apache/activemq-nms-amqp/pull/102#issuecomment-4526432390
Dear @Havret , thank you for your review. I applied the changes and updated the PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact
Re: [PR] Fix high CPU usage in case AmqpNetLite.Core 2.4.8+ [activemq-nms-amqp]
Posted by "Havret (via GitHub)" <gi...@apache.org>.
Havret merged PR #102:
URL: https://github.com/apache/activemq-nms-amqp/pull/102
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact