Solved

sockets and more.......

Posted on 2006-11-05
19
469 Views
Last Modified: 2012-08-13
reference here: http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_22024888.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.
0
Comment
Question by:Buffon
  • 8
  • 8
  • 2
19 Comments
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
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!
0
 
LVL 11

Author Comment

by:Buffon
Comment Utility
how can I reuse socket? and what is a short time for your opinion?
0
 
LVL 11

Author Comment

by:Buffon
Comment Utility
and I do null the reference by the way.
0
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
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!
0
 
LVL 11

Author Comment

by:Buffon
Comment Utility
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?
0
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
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!
0
 
LVL 11

Author Comment

by:Buffon
Comment Utility
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?
0
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
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!
0
 
LVL 11

Author Comment

by:Buffon
Comment Utility
so what do you recommend me to do? Not to use thread pool? and what about linger time, how can I change it?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
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!
0
 
LVL 11

Author Comment

by:Buffon
Comment Utility
ok I will try newer version, but again what about linger time?
0
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
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!
0
 
LVL 11

Author Comment

by:Buffon
Comment Utility
:) 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.
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 500 total points
Comment Utility
If the FIFO's remain with a newer server .... I rest my case.

;JOOP!
0
 
LVL 1

Expert Comment

by:bondzoro
Comment Utility
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?
0
 
LVL 1

Expert Comment

by:bondzoro
Comment Utility
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 ?

0
 
LVL 11

Author Comment

by:Buffon
Comment Utility
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.
0
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
:)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now