Hi,
I am working with the 0.7.0-SNAPSHOT indeed. 
This should do the same, I am testing it right now (if this does not leak, then 
it comes from the camel integration, but these actions are the same done by the 
camel component:

 public static void main(String[] args) throws Exception {
        try {
            int i=0;
            while(true){
                //Thread.sleep(100);  //IN MY EXAMPLE THE POLLING INTERVALL IS 
100MS
                i++;
                PlcConnection connection = new 
PlcDriverManager().getConnection("s7:tcp://192.168.178.10");
                PlcReadRequest.Builder builder = 
connection.readRequestBuilder();
                builder.addItem("default","%DB1.DBW0:WORD");
                PlcReadResponse response = builder.build().execute().get();
                logger.info("{} Response Code: {} for 
{}",i,response.getResponseCode("default"),response.getShort("default"));
                connection.close();
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

On 2020/02/27 16:37:49, Christofer Dutz <[email protected]> wrote: 
> Hi Etienne,
> 
> What version are you using? I know that Julian worked on quite some leaks and 
> memory leaks were one the main reasons for the Christmas refactoring. But he 
> also fixed a lot of things in the 0.6.0 branch. If you're already on 
> 0.7.0-SNAPSHOT (develop branch) this is something we should definitely 
> investigate.
> 
> Would it be possible to provide a testcase where I could locally reproduce 
> this behavior? Then I could let JProfiler loose on the example and see where 
> the memory is leaking to.
> 
> Chris
> 
> 
> 
> Am 27.02.20, 17:06 schrieb "Etienne Robinet" <[email protected]>:
> 
>     Hello,
>     after managing to do some read/write with camel, I tried to start 
> fetching at specific interval. My goal was being able to fetch at regular 
> pace (like every 500ms) to monitor some data. After running some tests, I 
> came across an error: 
>     
>      java.lang.OutOfMemoryError: Java heap space
>     
>     after rerunning some tests, I saw that the JVM will tak up to 4Gb before 
> the crash. After check netstat in Powershell, I realized I was having 50k+ 
> different ports occupied on my localhost! I don't know if this has been 
> lokked into yet or was never intended to be used like that, but after adding 
> some Logs, I can tell that with my route, the app creates a Polling Consumer 
> every tick that makes a plcCOnnection.close() when he's done. But after 
> shutting down the context, a Plc4xConsumer class will also shutdown a 
> connection. But still, in netsat I can see all these open connections for a 
> bit of time. If anyone has an idea, that will be great! Here the route: 
>     
>     <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"; 
> default-activation="lazy">
>         <camelContext id="S7-PLC-Context" 
> xmlns="http://camel.apache.org/schema/blueprint"; streamCache="true" >
>             <route>
>                 <from uri="timer://foo?fixedRate=true&period=1000" />
>                 <pollEnrich>
>                     
> <constant>plc4x:s7:tcp://192.168.178.10?address=%25DB1.DBW0:WORD</constant>
>                 </pollEnrich>
>                 <setHeader  headerName="fieldName">
>                     <constant>default</constant>
>                 </setHeader>
>                 <setHeader headerName="fieldQuery">
>                     <constant>%MW10:WORD</constant>
>                 </setHeader>
>                 <convertBodyTo type="java.lang.Short"/>
>                 <to uri="plc4x:s7:tcp://192.168.178.10" />
>                 <log message=" Response code: 
> ${body.getResponseCode(default)} at ${date:now:HH:mm:ss}" loggingLevel="INFO" 
> />
>             </route>
>         </camelContext>
>     </blueprint>
>     
>     
>     and the LOGGER :
>     17:04:55.883 INFO [pipe-bundle:start 67] Blueprint bundle 
> s7-camel/0.1.0.SNAPSHOT has been started
>     17:04:55.884 INFO [Blueprint Event Dispatcher: 1] Attempting to start 
> CamelContext: S7-PLC-Context
>     17:04:55.885 INFO [Blueprint Event Dispatcher: 1] Apache Camel 2.24.2 
> (CamelContext: S7-PLC-Context) is starting
>     17:04:55.886 INFO [Blueprint Event Dispatcher: 1] StreamCaching is 
> enabled on CamelContext: S7-PLC-Context
>     17:04:55.886 INFO [Blueprint Event Dispatcher: 1] JMX is enabled
>     17:04:55.912 INFO [Blueprint Event Dispatcher: 1] Instantiating new PLC 
> Driver Manager with class loader BundleDelegatingClassLoader(s7-camel [67])
>     17:04:55.913 INFO [Blueprint Event Dispatcher: 1] Registering available 
> drivers...
>     17:04:55.916 INFO [Blueprint Event Dispatcher: 1] Registering driver for 
> Protocol s7 (Siemens S7 (Basic))
>     17:04:55.925 INFO [Blueprint Event Dispatcher: 1] StreamCaching in use 
> with spool directory: 
> C:\karaf\data\tmp\camel\camel-tmp-e0de8e4a-1313-44d0-a309-e211b894bd4d and 
> rules: [Spool > 128K body size]
>     17:04:55.958 INFO [Blueprint Event Dispatcher: 1] Can read true can write 
> true can subscribe true
>     17:04:56.018 INFO [Blueprint Event Dispatcher: 1] Route: route10 started 
> and consuming from: timer://foo?fixedRate=true&period=1000
>     17:04:56.019 INFO [Blueprint Event Dispatcher: 1] Total 1 routes, of 
> which 1 are started
>     17:04:56.020 INFO [Blueprint Event Dispatcher: 1] Apache Camel 2.24.2 
> (CamelContext: S7-PLC-Context) started in 0.136 seconds
>     17:04:57.020 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] 
> Instantiating new PLC Driver Manager with class loader 
> BundleDelegatingClassLoader(s7-camel [67])
>     17:04:57.021 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] 
> Registering available drivers...
>     17:04:57.021 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] 
> Registering driver for Protocol s7 (Siemens S7 (Basic))
>     17:04:57.021 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] 
> Creating POLLING CONSUMER
>     17:04:57.038 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] Can 
> read true can write true can subscribe true
>     17:04:57.055 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] 
> doStart POLLING Consumer
>     17:04:57.055 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] 
> Creating read request
>     17:04:57.070 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] 
> POLLING Consumer closed is false
>     17:04:57.070 INFO [nioEventLoopGroup-519-1] CHANNEL CLOSED : true
>     17:04:57.075 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] Value 
> obtained java.lang.Short
>     17:04:57.077 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] Has 
> optimizer : true
>     17:04:57.078 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] 
> Writing data [0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>     17:04:57.087 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo]  
> Response code: OK at 17:04:57
>     17:04:58.021 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] 
> Creating POLLING CONSUMER
>     17:04:58.022 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] Can 
> read true can write true can subscribe true
>     17:04:58.038 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] 
> doStart POLLING Consumer
>     17:04:58.038 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] 
> Creating read request
>     17:04:58.041 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] 
> POLLING Consumer closed is false
>     17:04:58.041 INFO [nioEventLoopGroup-520-1] CHANNEL CLOSED : true
>     17:04:58.042 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] Value 
> obtained java.lang.Short
>     17:04:58.042 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] Has 
> optimizer : true
>     17:04:58.043 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo] 
> Writing data [0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>     17:04:58.047 INFO [Camel (S7-PLC-Context) thread #17 - timer://foo]  
> Response code: OK at 17:04:58
>     17:04:58.256 INFO [pipe-bundle:stop 67] Destroying container for 
> blueprint bundle s7-camel/0.1.0.SNAPSHOT
>     17:04:58.257 INFO [Blueprint Event Dispatcher: 1] Stopping CamelContext: 
> S7-PLC-Context
>     17:04:58.257 INFO [Blueprint Event Dispatcher: 1] Apache Camel 2.24.2 
> (CamelContext: S7-PLC-Context) is shutting down
>     17:04:58.258 INFO [Blueprint Event Dispatcher: 1] Starting to graceful 
> shutdown 1 routes (timeout 300 seconds)
>     17:04:58.259 INFO [Camel (S7-PLC-Context) thread #18 - ShutdownTask] 
> Closed connection false
>     17:04:58.260 INFO [nioEventLoopGroup-518-1] CHANNEL CLOSED : true
>     17:04:58.260 INFO [Camel (S7-PLC-Context) thread #18 - ShutdownTask] 
> Route: route10 shutdown complete, was consuming from: 
> timer://foo?fixedRate=true&period=1000
>     17:04:58.260 INFO [Blueprint Event Dispatcher: 1] Graceful shutdown of 1 
> routes completed in 0 seconds
>     
>     
>     
>     Etienne
>     
>     
> 
> 

Reply via email to