Fastest hashing algorithm?

Discussion in 'Java' started by howa, Jun 12, 2007.

  1. howa

    howa Guest

    conside an example like...

    you have 5 Servers, one user queue, and you want to distribute the
    users to these 5 servers, users come at different time, assume truely
    random

    a simple algorithm is to use Random to generate index 0..4 and assign
    the server.

    but think about it, if user come at random, why you need to use radnom

    i don't know the implementation of Random, but seems a little bit
    overkill the requirements...

    a simple approach is to `mod` the current time and assign the server,
    what do you abt this suitation?

    thanks.
     
    howa, Jun 12, 2007
    #1
    1. Advertising

  2. "howa" <> wrote in message
    news:...
    | conside an example like...
    |
    | you have 5 Servers, one user queue, and you want to distribute the
    | users to these 5 servers, users come at different time, assume truely
    | random
    |
    | a simple algorithm is to use Random to generate index 0..4 and assign
    | the server.
    |
    | but think about it, if user come at random, why you need to use radnom
    |
    | i don't know the implementation of Random, but seems a little bit
    | overkill the requirements...
    |
    | a simple approach is to `mod` the current time and assign the server,
    | what do you abt this suitation?

    I would assign each incoming user to the least busy server.
     
    Matt Humphrey, Jun 12, 2007
    #2
    1. Advertising

  3. howa

    Tom Hawtin Guest

    howa wrote:
    >
    > you have 5 Servers, one user queue, and you want to distribute the
    > users to these 5 servers, users come at different time, assume truely
    > random
    >
    > a simple algorithm is to use Random to generate index 0..4 and assign
    > the server.
    >
    > but think about it, if user come at random, why you need to use radnom
    >
    > i don't know the implementation of Random, but seems a little bit
    > overkill the requirements...


    Handling a user request is a relatively *HUGE* operation. Think how many
    cycles that will cost you, and guess how much creating a psuedo-random
    number costs.

    You can easily look at the implementation of Random. It's in the src.zip
    file in your JDK. Notice that (in recent versions) it doesn't so much as
    use a lock. Indeed, you could allocate round-robin. Just use a
    java.util.concurrent.atomic.AtomicInteger, and no need for locks.

    Tom Hawtin
     
    Tom Hawtin, Jun 12, 2007
    #3
  4. howa

    Mark Space Guest

    Matt Humphrey wrote:

    > I would assign each incoming user to the least busy server.


    I'm with Matt. I'm sure there's a simple way to get the load from a
    server, depending on your OS.

    A simpler interim solution might just be to keep track of how many user
    connections you have currently to each server. (This assumes users
    leave their connection "open" I guess.) Assign new users to the server
    with the least number of users connected.
     
    Mark Space, Jun 13, 2007
    #4
  5. howa

    Roedy Green Guest

    On Tue, 12 Jun 2007 11:40:02 -0700, howa <> wrote,
    quoted or indirectly quoted someone who said :

    >
    >you have 5 Servers, one user queue, and you want to distribute the
    >users to these 5 servers, users come at different time, assume truely
    >random


    Before you waste effort optimising, you must measure the time taken to
    make sure you are chewing at the bottleneck.

    Almost certainly optimising this will have no noticeable effect unless
    you were doing task scheduling inside the OS.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Jun 13, 2007
    #5
  6. howa

    howa Guest

    > I would assign each incoming user to the least busy server.

    I agree, but sometime checking the server status introduce some
    overheads.

    e.g. the JSP page need to store all the servers status into a
    persistent storage and check for every requests.

    So that's why many people still using DNS round-robin kind of for load
    balacing..
     
    howa, Jun 13, 2007
    #6
  7. howa

    EricF Guest

    In article <>, Roedy Green <> wrote:
    >On Tue, 12 Jun 2007 11:40:02 -0700, howa <> wrote,
    >quoted or indirectly quoted someone who said :
    >
    >>
    >>you have 5 Servers, one user queue, and you want to distribute the
    >>users to these 5 servers, users come at different time, assume truely
    >>random

    >
    >Before you waste effort optimising, you must measure the time taken to
    >make sure you are chewing at the bottleneck.
    >
    >Almost certainly optimising this will have no noticeable effect unless
    >you were doing task scheduling inside the OS.


    I missed the original post but I do agree with Roedy. Are all the user tasks
    similar in resource usage and run time?

    Eric
     
    EricF, Jun 14, 2007
    #7
  8. howa

    Twisted Guest

    On Jun 14, 12:24 am, (EricF) wrote:
    > I missed the original post but I do agree with Roedy. Are all the user tasks
    > similar in resource usage and run time?


    And are all the servers comparable in capacity (similar RAM, similar
    CPU, similar bandwidth...)?
     
    Twisted, Jun 14, 2007
    #8
  9. howa

    Roedy Green Guest

    On Tue, 12 Jun 2007 11:40:02 -0700, howa <> wrote,
    quoted or indirectly quoted someone who said :

    >you have 5 Servers, one user queue, and you want to distribute the
    >users to these 5 servers, users come at different time, assume truely
    >random


    why would random do better than round robin?

    If you want to get clever, I think you need a measure of who is most
    lightly loaded and give the new user to that server.

    On Vista there is a measure of disk and CPU time utilisation that even
    desk gadgets can get hold of. You would need a little JNI to gather
    those stats for your servers.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Jun 15, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Pernkopf
    Replies:
    0
    Views:
    564
    Michael Pernkopf
    May 27, 2004
  2. Richard Cavell

    Fastest sort algorithm?

    Richard Cavell, Mar 31, 2005, in forum: C++
    Replies:
    3
    Views:
    3,896
  3. yee young han
    Replies:
    2
    Views:
    508
    Jerry Coffin
    May 22, 2005
  4. Arthur Chan
    Replies:
    0
    Views:
    188
    Arthur Chan
    Apr 27, 2009
  5. rob
    Replies:
    4
    Views:
    242
    Michele Dondi
    Sep 29, 2004
Loading...

Share This Page