Search code examples
mulesoftanypoint-studio

MuleSoft Anypoint - create a custom thread pool connector for a Logger


We are experiencing performance issues when using the MuleSoft Log connector at a high TPS rate (over 5,000 TPS). It appears that in Synchronous mode, it quickly consumes all threads from the main thread pool and becomes a bottleneck. It also seems that creating and assigning a dedicated thread pool for the Log connector is not possible.

I am wondering if it's a good practice to create two custom connectors:

  1. A custom thread pool connector that creates a thread pool to be used by other connectors.
  2. A custom logger that employs an async logger like Logback or Log4j-2 and utilizes the custom thread pool connector.

If this is not the best practice (or not possible at all), what is the most effective way to improve the logging performance of the existing logger?

We tried minimizing the usage of the Log connector, but it seems that even at the minimum usage we still get bad performance.


Solution

  • No, it is actually a bad practice.

    Recommended practice (TL;DR):

    • Use asynchronous log4j2 loggers, which are there in a default project in Anypoint Studio and the recommended usage for performance.
    • Minimize logging use. Maybe your application is not compatible with logging or should be used very sparingly.
    • Use updated versions: use the latest possible Mule runtime version with the latest patches.

    Detailed explanation:

    • A thread pool is usually a performance bottleneck under heavy load. Libraries like log4j2 use more innovative approaches like asynchronous logging and the Disruptor pattern instead of thread pools.
    • Exporting a thread pool from a Mule connector would be actually bad practice. See MuleSoft Coding Practices and General Coding Rules. A Mule connector/module is not and should not be just a Java library.
    • Threads actually consume resources, they are not free.
    • Have you tested using Logback or some other logging implementation? Since Mule doesn't support them that would actually require a new module/connector for that. You would also have to test the performance and locking behavior under your application load just to see if there are any improvements.
    • Why are you even trying to use Synchronous logging? Do you have any special requirements?
    • This feels like an XY Problem. I recommend to investigate why threads are locking instead. That seems the real problem, that may or not be related to Log4j2 logging. After that if you want open a new question with information about that issue.

    Note: there is no MuleSoft Log connector. The Logger component is a built-in feature of the Mule runtime.