michele-tramonti commented on issue #2229:
URL: https://github.com/apache/plc4x/issues/2229#issuecomment-3350327597

   I experienced this issue with s7 and opcua too: to mitigate it I made a 
little change the source code of classes RequestTransactionManager (used by 
opcua driver and others) and S7ProtocolLogic (used by S7).
   Originally in both classes there was a creation of a new ExecutorService 
(creating threads plc4x-tm-thread-%d and plc4x-app-thread-%d respectively).
   It seems to me that every request made with the same connection (i.e. using 
the cached connection) creates a new object of RequestTransactionManager (in 
case of non-s7 driver) or S7ProtocolLogic (in case of S7), creating new pool of 
threads without destroyng the old ones.
   So I created a class called SharedExecutor like this:
   ```
   
   public class SharedExecutor {
       /**
        * Used by opcua driver and others (but not s7)
        */
       private static final ExecutorService tmExecutor = 
Executors.newFixedThreadPool(
               10,
               new BasicThreadFactory.Builder()
                       .namingPattern("plc4x-tm-thread-%d")
                       .daemon(true)
                       .priority(Thread.MAX_PRIORITY)
                       .build()
       );
   
       /**
        * Used only by s7 driver
        */
       private static final ExecutorService appExecutor = 
Executors.newFixedThreadPool(
               10,
               new BasicThreadFactory.Builder()
                       .namingPattern("plc4x-app-thread-%d")
                       .daemon(true)
                       .priority(Thread.MAX_PRIORITY)
                       .build()
       );
   
       public static ExecutorService getTmExecutor() {
           return tmExecutor;
       }
   
       public static ExecutorService getAppExecutor() {
           return appExecutor;
       }
       
   }
   
   ```
   and using those shared Executors insted of the original ones:
   
   original code in RequestTransactionManager:
   
   ```
   final ExecutorService executor = Executors.newFixedThreadPool(4, new 
BasicThreadFactory.Builder()
                                                       
.namingPattern("plc4x-tm-thread-%d")
                                                       .daemon(true)
                                                       
.priority(Thread.MAX_PRIORITY)
                                                       .build());
   ```
                                                       
   new code:
   
   `final ExecutorService executor = SharedExecutor.getTmExecutor();`
   
   there are also few little changes to avoid shutting down the shared executor 
in those classes.
   
   I see it's working but I don't know if, generally speaking, it's a 
meaningful solution, or only a quick and dirty patch that can cause other 
issues... that's why I made no pull request...
   
   what do you think?
   
   I'm very interested in a netty-free version of plc4j: is there any news on 
that?
   
   thank you
   
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to