B4J Question About WebSocket Threads, Map Collections and SQL Connections

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!
I have some questions about websocket instances/threads.
I have implemented a websocket server with many subs in the websocket class, that call SQL connections to a MariaDB database, a second MySQL database and creating many Map collection objects.
The SQL connections are opening from pools declared to Main module and after usage they are closed.
The result is some days after the server starts running, I have a large memory usage. The Eclipse MAT analyser, shows that the largest amount of memory used, comes from:

1. java.util.concurrent.ConcurrentHashMap$Node (40 MB of memory - 35% of usage)
2. com.mysql.jdbc.JDBC4Connection (29 MB of memory - 25% of usage)


I think the problem is the concurrent calls and creations of such objects inside every websocket thread that Garbage Collector does not anticipate to destroy them in a proper time manner.

My main question is: If I move the subs creating maps and calling SQL connections to a Code module and websocket threads make calls to them, will the program continue to create such objects for every concurrent thread?

Another question is: If the solution is to move all these subs to a code module, which is the best method to call them from websocket instances?
Direct call like: WsUtils.TestSub(data as map)?
Using CallSub or CallSubDelayed?

How to ensure that these objects will be destroyed as soon as possible?

Thank you in advance!
 
Last edited:

OliverA

Expert
Licensed User
Longtime User
120mb usage is not that bad. As to your maps, you need to provide some code as to what you are doing now.
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
Hello Oliver!
Thank you for your response!
It's a little difficult to provide a portion of code to see what I do, so I attach the WebSocket Class in order to give you a complete view.
About the memory usage, every day I have an increment of 60 - 90 MB, so after some days may it will be very bad!!!
The numbers I provided to my first post are the results after a full Garbage Collection.

Thank you in advance!
 

Attachments

  • PushB4A.bas
    177.4 KB · Views: 315
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…