Link to home
Start Free TrialLog in
Avatar of Buffon
BuffonFlag for Israel

asked on

sockets and more.......

reference here: https://www.experts-exchange.com/questions/22024888/Too-many-open-files.html

ok, I run thos lsof prog, and I got 350+ open file descriptors for my java process.....no good........
I see in there 100+ of those:

COMMAND   PID USER   FD   TYPE     DEVICE     SIZE     NODE NAME
java    11917 root  452r  FIFO        0,5          39355157 pipe
java    11917 root  453r  FIFO        0,5          39274366 pipe
java    11917 root  454w  FIFO        0,5          39274366 pipe
java    11917 root  455w  FIFO        0,5          39355157 pipe
java    11917 root  456w  FIFO        0,5          39377724 pipe

and I have no idea what is it, I dont use pipes?!?

also there are a lot of those:
java    11917 root   14u  IPv6   38332031               TCP server.<mydomain.com>:22005->n220246244233.<clientdomain>.com:3159 (CLOSE_WAIT)

I do close the sockets but I see from this that it waits for close from client or something, but i waits too long, what I can do?


so practicaly its 2 questions there.
Avatar of sciuriware
sciuriware

Can't you re-use sockets? I think you are opening lots of them is a short time.
Besides, not only close the sockets, but also null the references.

;JOOP!
Avatar of Buffon

ASKER

how can I reuse socket? and what is a short time for your opinion?
Avatar of Buffon

ASKER

and I do null the reference by the way.
1000 sockets per seconds exists, but causes problems like these.
Reuse by keeping connections open and sending logical closes:
sending a certain packet to indicate change of use.
The problem you are experiencing has to do with the linger-time in the server. May be not easily configured.
;JOOP!
Avatar of Buffon

ASKER

1) its not even close to 1000 sockets per minute.
2) cannot reuse like this because client disconnects for real.
3) how can I configure linger time and what is it?
4) is it possible that pipes are from MySQL connections? Is it possible that MySQL connection library has a leak?
You are obvious running a flavour of UNIX or LINUX,
a FIFO is a pseudo file on disk, opened for write by an arbitrary process,
and written to a certain amount before it goes to sleep,
while an aother arbitrary process can read from this file, waking up sleeping writers,
but going to sleep itself when the file becomes empty.
I presume that you are using a network-simulation on disk.
In that case the simulation is rather bad in that the reader is not notified
when the writer disconnects from the FIFO.

1) I see
2) now I understand
3) in this case the problem is in the software you are using.
Linger time is the time that a connection is kept alive by a receiver before removing it.
But here it looks like the receiver is simply a FIFO reader and that goes on forever, unless someone deletes the FIFO.
4) Connections to MYSQL should be made to an application server that does direct database access.
The client(s) should connect to the server and not interfere with MYSQL directly (if they could).

Resume: I wonder what strange construct you are using that fakes connections via FIFO's.

;JOOP!
Avatar of Buffon

ASKER

1) ok, I will explain about my application. The statistics are from my application server, to which clients connect and it connects to database. There are a group of clients per thread in application server, I use Selector to go over all sockets. There is 1 connection per thread, and its persistent till the thread is close. The threads are closed, but probably cached by JVM because I use Executors.newFixedThreadPool. I explicitly close all the sockets and connection in the end of thread.
anything else to explain? :)

2) I use mysql-connector-java-3.1.10, may be it has the leak? should I use other driver? I know jdk 1.6 introduce JDBC 4.

3) any other possible reason?
That is beyond my knowledge.
My (conservative) feelings have make me avoid some 'new' developments
because they go quicker than they come.
In a server I would gladly create a thread per connection and release it at close.
And I would use one per client, fearing connections to remain somewhere, frustrating even the GC.
I've written very large applications with very many threads and I'm convinced that JAVA
is strong enough to not need pools for that purpose.

;JOOP!
Avatar of Buffon

ASKER

so what do you recommend me to do? Not to use thread pool? and what about linger time, how can I change it?
I still don't see where those FIFO's were created.
I don't know much about MYSQL, might it be an old version?

;JOOP!
Avatar of Buffon

ASKER

ok I will try newer version, but again what about linger time?
From the JAVADOC (if you don't have it, download it!):
Class Socket

setSoLinger

public void setSoLinger(boolean on,
                        int linger)
                 throws SocketException

    Enable/disable SO_LINGER with the specified linger time in seconds. The maximum timeout value is platform specific. The setting only affects socket close.

    Parameters:
        on - whether or not to linger on.
        linger - how long to linger for, if on is true.
    Throws:
        SocketException - if there is an error in the underlying protocol, such as a TCP error.
        IllegalArgumentException - if the linger value is negative.
    Since:
        JDK1.1
    See Also:
        getSoLinger()

;JOOP!
Avatar of Buffon

ASKER

:) sorry, of course I have it, I thought its some kind of Linux option. thanks. I will not close this question for now, may be someone else will know about pipes.
ASKER CERTIFIED SOLUTION
Avatar of sciuriware
sciuriware

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
DId you ever check how many active database connections are there?
Are you closing database connections explicitly ?
Is there any max_limit set on no of database connections opened from application server if you are using a connection pool mechanism?
And one thing. when client connects to your server when an each connection has one socket communication open
I am sure you will have one OutputStream open to write any data to cleint and one InputStream open to read data from cleint connected.
Are you closing these streams i.e Input and Output steams explicitly ?

Avatar of Buffon

ASKER

1) I have one open connection to mysql opened in each thread, thread finishes, connection closed. no connection pooling.
2) I use nio, so no streams are involved, I interact with SocketChannel. sockets are also closed explicitly in the end of thread.