Discussions

Performance and scalability: Multithreaded programming

  1. Multithreaded programming (11 messages)

    Hello,
    I have an application that has some 10 resultsets(RS) as an output for many different users.
    So the
    user 1 (U1) has the 10 RS (R1, R2, R3..... )
    user 2 (U2) has the 10 RS (R1, R2, R3..... )
    ..................
    .................
    user n (Un) has the 10 RS (R1, R2, R3..... )

    Then I am itereating all the 10 RS. and populating the Models(Getter setter methods classes).
    this is taking lot of time as the resultsets have some millions of records and there are thousands of users.

    Can I change my application so that all the users will be handled parallely through the multithreaded way.
    I mean, is the threading will benefit the performance issues?

    All the replys will be highly appreciated.

    Thanks in advance.
    Suhas S

    Threaded Messages (11)

  2. Multithreaded programming[ Go to top ]

    Hey Suhas

    Your application seems to be heavily loaded.

    Can you give some more details about the architecture and technology, so that the actual constraints can be judged. This might help in attacking thr true bottlenecks in the system.

    Cheers,
    Ajay
  3. Thanks for the reply Ajay,
    Actually this application is a Java Application (Jdk1.3) and on Solaris Machine with v high configuration. The database we are using is Sybase 12.x
    Is this info. you are asking for?
    Actually my idea is to deal populate the models for all the users in parallel way. Is this possible? I mean will this reduce the time or will just increase the memory heap.
    Thanks
    Suhas S
  4. Multithreaded programming[ Go to top ]

    unless you got more than 1 CPU, multi threading your 10 db queries is only gonna make all of them 10 times slower on avg (plus or minus, given db caching, disk i/o perf +/- raid, or even balanced DB server tier).

    And even with 10 cpu, if you have avg 100 concurrent queries (let's say 10 users querying), is not gonna change a things to multithread, since all CPU are all occupied already.

    Rule of thumb, when a system is saturated, multithreading doesn't help, even waste cpu through context switching.

    If your CPU(s) are mostly idle (~10%), then chances are the time wasted is at db server accesing disk (and network latency if db tier). In which case you better have a raid and a 1 gigabit/s network card (+very optimized tcp/ip stack).

    In other words, there is no point in multithreading if the code to be multithreaded is not blocking/waiting, because CPU is not idle in non-blocking code (beside few memory access cycle that occurs anyway in any code) and multithreading just adds context switching.

    If you have hyperthreaded cpu, multithreading could help if threads are doing very different type of work (i/o, memory, arithmetic) which is not what you intend to do.
  5. Multithreaded programming[ Go to top ]

    Thank you very much!!
    Regards
    Suhas
  6. Multithreaded programming[ Go to top ]

    Quartz,

    Does multi-threaded code need to run on a multi-processor cpu to realize any benefit from the multi-threading? In other words, does a single processor CPU run threads consecutively or in parallel?

    Thanks.
  7. Multithreaded programming[ Go to top ]

    Well, back to computer architecture basics
     Traditional von Newman machines are called SISD (Single Instruction stream Single Data stream) machines can only do one job at any given instant of time. Thats why Parallel processing machines have multiprocessors or are distributed in nature.

    Anyways, i dont really have the low down on Hyper Threading technology but otherwise, one cpu can process one instruction at any given instance of time.

    I dont know whether Suhas has a lot of load on his system's processors or not. But like Quartz said, it makes sense to have threading only when u expect ur processor is going to remain free for a while. Otherwise, its the same bottleneck, this way or that way.
    What u might need is better faster hardware, or maybe a redesign into a distributed system ( I know im dreamin with this, but what the hell)
    Cheers
    Ajay
  8. Multithreaded programming[ Go to top ]

    Thanks Ajay.

    So, are these two statements true?

    Code that is deployed on a single processor CPU will not realize any benefit from multi-threading. True or false?

    A 'synchronized' code block is irrelevant when deployed on a single processor CPU. True or false?

    cheers.
  9. Multithreaded programming[ Go to top ]

    The first statement is conditional.
    It all depends on how much time your CPU is free.

    eg. Lets say ur program needs to do two jobs
    1. Read a line from the keyboard and use the data in some calculation.
    2. Send a mail to someone ( the mail has nothing to do with the 1st job)

    So while u wait for the user to key in data( and ur CPU does nothing during this time), u would be better off spawning a thread and going ahead with sending the mail.

    However, if ur program has to do immense processor intensive calculation(without waiting for anything), and send the mail too, then ur not getting much out of spawning new threads for the mailing.


    The 2nd statement is not true.
    This is because if u spawn different threads, that are going to use the same object in memory, ur processor will switch between these threads to do something called "timesharing"( which thread gets how much time depends on the threadng model and the priority of each thread). Thus it is possible that while Thread 1 is using object 1, it has to move out of the cpu to give thread 2 a chance to run. if object 1 is not synchronized, thread 2 can change its value before thread 1 runs again.
    That is why u need synchronized code even if u have just one processor.

    I hope that clarifies ur doubt.

    Cheers
    Ajay
  10. Multithreaded programming[ Go to top ]

    Thanks for the thorough explanation!
  11. interresting reading: MAJC[ Go to top ]

    interresting reading:
    http://arstechnica.com/cpu/4q99/majc/majc-1.html
  12. Hello,I have an application that has some 10 resultsets(RS) as an output for many different users.So the user 1 (U1) has the 10 RS (R1, R2, R3..... )user 2 (U2) has the 10 RS (R1, R2, R3..... )...................................user n (Un) has the 10 RS (R1, R2, R3..... )Then I am itereating all the 10 RS. and populating the Models(Getter setter methods classes).
    If you keep open more than two or three result sets, probably you are going to run out of cursors. I have seen a lot of problems related with cursors, and all of then got solved redesigning the application to use only a few open result sets.
    this is taking lot of time as the resultsets have some millions of records and there are thousands of users.
    If your result set returns millions of records, maybe you should try to adjust the WHERE clauses in order to read less records. The less records you move through the network, the faster your application (and databases) run.


    Jose Ramon Huerga
    http://www.terra.es/personal/jrhuerga/