Home Help Center

multiple threads, single connection problem

ywtsangywtsang Member Yiu WingOrganization: yesasiaProject: search engine
i have read the documentation and verified the codes that though we have multiple threads, we only have estabished one single connection to the server, that eventually multiple threads will block on this synchroize block in the following method:

<code>
ConnectionI.sendRequest
</code>

i want to seek for verification of my understanding and any suggestion if appropriate

this is our current setup:

mutiple ice servers are setup with different IPs, but clients will connect to these servers by another single IP, and that IP will forward to either one of the actual ice server ip by our load balancer
(this was a historical setup...)

now, the situation is
once our client is connected to one of the ice server, it never change to other servers (this is expected after i read the documentation and verify that by code)

but we also find that only one single connection is created, even we have multiple client threads are created to serve the requests

the question is
- even we have multiple threads, eventually all those threads will be serialized to wait for the single connection ?
- if it is so, is there any mean to have multiple connections per single proxy? (without using the IceGrid for clustering/failure over/load balancing)

Comments

  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Welcome to the forum!

    You can force a proxy to use a different connection by assigning it a unique "connection id" (see this this section of the manual). You can use this however you like; for example, you can give each proxy a different id, in which case each proxy creates its own connection. Another option is to create a pool of ids if you are concerned about creating too many connections.

    Here's a code sample:
    // Java
    Ice.ObjectPrx proxy = ...
    Ice.ObjectPrx proxy1 = proxy.ice_connectionId("id1");
    
    Cheers,
    Mark
  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    I forgot to respond to this question:
    ywtsang wrote: »
    even we have multiple threads, eventually all those threads will be serialized to wait for the single connection ?
    Multiple threads can share a single proxy and a single connection. If Thread A is blocked waiting for the response to a twoway invocation, Thread B can still make invocations on the same proxy without being blocked by the activities of Thread A.

    Let us know if you need more information.

    Mark
  • ywtsangywtsang Member Yiu WingOrganization: yesasiaProject: search engine
    something doubtful is found

    we find that the server has warning message on the thread pool:

    Size=10, SizeMax=10, SizeWarn=10
    warning: thread pool `Ice.ThreadPool.Server' is running low on threads


    and try to read the thread dump, and it also shows that multiple threads are running to serve the request

    so that means we still can serve for multiple requests even we have one single connection?
  • ywtsangywtsang Member Yiu WingOrganization: yesasiaProject: search engine
    mes wrote: »
    Welcome to the forum!

    You can force a proxy to use a different connection by assigning it a unique "connection id" (see this this section of the manual). You can use this however you like; for example, you can give each proxy a different id, in which case each proxy creates its own connection. Another option is to create a pool of ids if you are concerned about creating too many connections.

    Here's a code sample:
    // Java
    Ice.ObjectPrx proxy = ...
    Ice.ObjectPrx proxy1 = proxy.ice_connectionId("id1");
    
    Cheers,
    Mark

    thanks for the quick response,

    does that mean we need to create multiple proxies? i.e. we need to pick up one from the list of created proxies when needed?
  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    ywtsang wrote: »
    so that means we still can serve for multiple requests even we have one single connection?
    Yes, that's correct. An object adapter can service up to N simultaneous invocations, where N is the maximum size of the thread pool.

    Cheers,
    Mark
  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    ywtsang wrote: »
    does that mean we need to create multiple proxies? i.e. we need to pick up one from the list of created proxies when needed?
    You don't necessarily need to use the same proxy object. If you create a proxy with the connection id of an existing connection, that proxy will share the connection with other proxies having the same id.

    Cheers,
    Mark
Sign In or Register to comment.