B4J Question JRDC2 and MySQL memory usage

marcick

Well-Known Member
Licensed User
Longtime User
I have a JRDC2 application on a server that receives data packets and store in MySql db.
Sometimes, let's say once in a month, I have a crash that require a restart of the app.
Though I have various logs I still have to understand what is going wrong.

But here I just want to ask opinions about this: running task manager I have noted that after some hours the app is running, the memory usage of the mysqld process (one of them, I see there are two) increase.
At startup it increase of about 100MB in 3 or 4 hours, then looks like it sets at around 500MB after some days.

Should it be considered normal or my code can have bugs that forget to close something somewhere ?


New Bitmap Image.jpg
 

marcick

Well-Known Member
Licensed User
Longtime User
well, I often have errors that are trapped by this sub in main

B4X:
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean

There i write the errors in a log file and are like these

B4X:
2018-11-19 18:37:47 - RDCHandler_Handle error, method query2, (IOException) java.io.IOException: An existing connection was forcibly closed by the remote host
2018-11-19 18:41:09 - RDCHandler_Handle error, method batch2, (IllegalStateException) java.lang.IllegalStateException: WRITER
2018-11-19 19:13:30 - RDCHandler_Handle error, method query2, (TimeoutException) java.util.concurrent.TimeoutException: Idle timeout expired: 30003/30000 ms
2018-11-20 11:09:23 - RDCHandler_Handle error, method query2, (EofException) org.eclipse.jetty.io.EofException: Early EOF
2018-11-20 12:18:14 - RDCHandler_Handle error, method batch2, (IllegalStateException) java.lang.IllegalStateException: WRITER
2018-11-20 15:52:17 - RDCHandler_Handle error, method batch2, (IllegalStateException) java.lang.IllegalStateException: WRITER
2018-11-20 15:53:13 - RDCHandler_Handle error, method batch2, (IllegalStateException) java.lang.IllegalStateException: WRITER
2018-11-20 16:22:51 - RDCHandler_Handle error, method batch2, (IllegalStateException) java.lang.IllegalStateException: WRITER
2018-11-20 16:27:39 - RDCHandler_Handle error, method batch2, (IllegalStateException) java.lang.IllegalStateException: WRITER
2018-11-21 19:15:46 - RDCHandler_Handle error, method batch2, (IllegalStateException) java.lang.IllegalStateException: WRITER
2018-11-21 20:23:27 - RDCHandler_Handle error, method query2, (ZipException) java.util.zip.ZipException: invalid distance too far back
2018-11-22 07:47:14 - RDCHandler_Handle error, method batch2, (IllegalStateException) java.lang.IllegalStateException: WRITER

Normally the app continues without problems (it seems) but once in a month I see in the JRDC console many errors and I have to close it and restart.
Because the errors I see are related to the communication with MySql, I wonder if I'm doing something wrong somewhere, leaving floating resources that cause the increase in memory usage (though it isn't the JRDC application that increase memory but the mysqld process).
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Ok. But do you think is normal that the memory usage of mysqld process increase ?
Yesterday it was 402 MB and today is 428.
 
Upvote 0

jimmyF

Active Member
Licensed User
Just for your information:
I have two separate .jar file running on my Win 2012 R2 server that I access remotely on a regular basis, using separate MySql 5.7 connections accessing multiple dbs, and they have been running continuously for 18 days (since last reboot) without a significant change in memory usage; neither the java nor the MySql.

I am not sure where to look but do you close RecordSets when you are finished with them?
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
This is interesting, thanks.
Now it is 430 (428 this morning). A little increase but an increase.
So I suspect something is not correct in my code.
Normally my code blocks are like this

B4X:
Dim Con As SQL=Main.rdcConnector1.GetConnection  
Dim Cursor1 As ResultSet=Con.ExecQuery2("SELECT * from config WHERE Vid=?", Array As Object(V_ID))
Do While Cursor1.NextRow
      ......
Loop
If Con <> Null And Con.IsInitialized Then Con.Close
If Cursor1.IsInitialized Then Cursor1.Close

But I will check again all the code.
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
It won't be you not closing connections unless you have radically altered your MySQL configuration. By default MySQL terminates a connection after it being idle for 8 hours.

You can see the number connections to a MySQL server by using the "show processlist"" command. There are lots of configuration options for memory on a MySQL server and it can be quite normal to see the memory usage growing depending on how it has been configured and the type of DB engine (InnoDB, MyISAM etc) you are using.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Thank you.
I have the latest version of wamp server but I didn’t do any changes in MySQL configuration.
Interesting: can I see the number of connections with phpmyadmin also ? (I’m not very familiar with MySQL console).
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
For connections not being closed look for "Sleep" in the Command column and a large number in the time column. The time column is in seconds.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I’ll monitor it, though if it were true I should see very high value as time after some days and it isn’t. So as you say MySQL close by itself connections eventually left open. And my problem is not here.
Thank you very much.
 
Upvote 0
Top