Home Help Center

Too many open files with IceJ

lucsatlucsat Member Jordi RubioOrganization: Grupo IntercomProject: I+D
Hi,

I have a simple Ice Client/Server application in a Linux environment (Fedora Core 4 in the client side and Mandriva LE 2005 in the server side). The server is a simple Ice.Application, and the client is a Java servlet.

This is the icebox.properties:

Ice.ThreadPool.Client.SizeMax=10
Ice.ThreadPool.Server.SizeMax=10

I run 20 concurrent requests, and all works fine. I run 20 more concurrent, and the client hasn't problems. But if I run 20 more concurrent requests, the client (jakarta tomcat) throws a lot of exceptions:

error: cannot create thread pool for connection:
Ice.SocketException
error = 0
at IceInternal.Network.createTcpSocket(Network.java:104)
(...)
Caused by: java.net.SocketException: Too many open files
at sun.nio.ch.Net.socket0(Native Method)

What's the matter?

I attach the server and client main classes in this issue.

Thanks a lot for helping me!

P.D.: I'm testing ICE for future developments. We have already programmed a medium multithread search java program, and we want to know if ICE is faster than a classical multithreading implementation.

Comments

  • dwaynedwayne St. John's, NewfoundlandMember Dwayne BooneOrganization: ZeroC, Inc.Project: Internet Communications Engine
    Please see http://www.zeroc.com/vbulletin/showthread.php?t=1697 for our support policy.
  • lucsatlucsat Member Jordi RubioOrganization: Grupo IntercomProject: I+D
    Hi dwayne,

    I apologize for the mistake... ;) (i'm newbie)

    Best regards...
  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi,

    Creating a communicator is an expensive operation, and is not something I would recommend doing for every HTTP request.

    Rather, your servlet should create the communicator once (e.g., in the servlet's init method) and use that same instance for every HTTP request. Furthermore, if all HTTP requests result in invocations on the same Ice object, then your servlet should also create the proxy in the init method.

    For example:
    public class MyServlet extends HttpServlet
    {
        public void init() throws ServletException
        {
            try
            {
                String[] args = {};
                _communicator = Ice.Util.initialize(args);
                Ice.ObjectPrx proxy = _communicator.stringToProxy("...");
                _searcher = SearcherPrxHelper.checkedCast(proxy);
                if(_searcher == null)
                {
                    throw new UnavailableException("Invalid proxy");
                }
            }
            catch(Exception ex)
            {
                UnavailableException e = new UnavailableException("Ice failure");
                e.initCause(ex);
                throw e;
            }
        }
    
        public void destroy()
        {
            if(_communicator != null)
            {
                try
                {
                    _communicator.destroy();
                }
                catch(Exception ex)
                {
                    // Ignore
                }
            }
        }
    
        ...
    
        private Ice.Communicator _communicator;
        private SearcherPrx _searcher;
    }
    
    We'll investigate whether the exception you saw is the result of a problem in Ice.

    Take care,
    - Mark
  • lucsatlucsat Member Jordi RubioOrganization: Grupo IntercomProject: I+D
    Fantastic!

    Hi Mark!

    It works!!! Thanks a lot for your time!!! :D

    Best regards!
Sign In or Register to comment.