Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sockets and more.......

Posted on 2006-11-05
19
Medium Priority
?
482 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
  • 2
19 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 17879239
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
ID: 17879282
how can I reuse socket? and what is a short time for your opinion?
0
 
LVL 11

Author Comment

by:Buffon
ID: 17879422
and I do null the reference by the way.
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 24

Expert Comment

by:sciuriware
ID: 17879699
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
ID: 17879740
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
ID: 17879856
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
ID: 17879947
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
ID: 17879970
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
ID: 17879979
so what do you recommend me to do? Not to use thread pool? and what about linger time, how can I change it?
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17880008
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
ID: 17880070
ok I will try newer version, but again what about linger time?
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17880377
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
ID: 17880407
:) 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 2000 total points
ID: 17880421
If the FIFO's remain with a newer server .... I rest my case.

;JOOP!
0
 
LVL 1

Expert Comment

by:bondzoro
ID: 17936346
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
ID: 17936353
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
ID: 17936362
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
ID: 18165399
:)
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

705 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