Home Help Center

Simple using threads

ramayanaramayana Member Stanislaw ArtymowskiOrganization: Instytut Monitorowania MediówProject: Testing and learning ICE
Hi again,
Since i sucesfulled integrated Client with postgreSQL function i can make query and postgreSQL is connecting to server, but i would like to make that serwer will create another thread for each new query, because if i make select someFunction(generate_series(1, 10000))

it will cost a lot of time. How can i do that on the serwer? In the simple way of course.

Thanks for any help!

Comments

  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    You can configure the server thread pool to have more threads available for dispatch requests, the default is 1, add this properties to your server configuration:
    [PHP]
    Ice.ThreadPool.Server.Size=1
    Ice.ThreadPool.Server.SizeMax=10
    [/PHP]

    See:

    Thread Pools - Ice 3.4 - ZeroC
    Thread Pool Design Considerations - Ice 3.4 - ZeroC

    If you plan to have many long running operations you can also consider using AMD (Asynchronous Method Dispatch) on the server.

    See:

    Asynchronous Method Dispatch (AMD) in C++ - Ice 3.4 - ZeroC

    There is an AMD demo in demo/Ice/async directory.
  • ramayanaramayana Member Stanislaw ArtymowskiOrganization: Instytut Monitorowania MediówProject: Testing and learning ICE
    Thanks Jose,
    I set properties like you've wrote but results wasn't great, i mean one that kind of query was treated like one thread, and that is quite good, but i'm wonderng can it could working faster. I'm trying to implement it with AMD based on demo, but i get error about creating an abstract class. I attach my testing project. If someone could look on that and check what i did wrong i would be grateful.

    FILE
  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi Stanislaw,

    About your AMD problem , the definition of you operation doesn't match the generated code, it should be:
    [PHP]
    virtual void CalculateSqrt_async(const SqrtModule::AMD_ISqrt_CalculateSqrtPtr& cb, Ice::Double, const Ice::Current&);
    [/PHP]

    The AMD version of the operation, has as first argument a generated CB, and then one argument for each in-argument defined in Slice , plus Ice::Current argument.

    About thread pool configuration, you can also try to set Ice.ThreadPool.Server.Size to a greater value, this will avoid the overhead of create/destroy threads.

    If you set Ice.ThreadPool.Server.Size=10, there will be always 10 threads in the server thread pool and you will be able to dispatch 10 concurrent request each one in a different thread.

    With the previous configuration i posted, there is always 1 thread, but thread pool is allowed to grow until 10 threads.

    If you go the AMD route, the async demo is just an example, the WorkQueue adds a delay to simulate long running operations, and also serialize the operations, you probably don't want to do that but instead have some kind of thread pool dedicated to execute these long running operations.
  • ramayanaramayana Member Stanislaw ArtymowskiOrganization: Instytut Monitorowania MediówProject: Testing and learning ICE
    Thanks Jose, you're fast!
    Of course you're right about my AMD problem.

    This Ice.ThreadPool.Server.SizeMax=10 is great but new threads are created when i make, i.e. two query in the same time - then server creating two treads but one query calling i.e. 10000 postgreSQL function and i'm wondering if i can make faster one query, but it is not so important... at least now.

    Thanks for your help and patient.

    Best regards
Sign In or Register to comment.