View | Details | Raw Unified | Return to bug 49822
Collapse All | Expand All

(-)tomcat-connectors/native/common/jk_lb_worker.c (-2 / +59 lines)
Lines 65-70 Link Here
65
    JK_LB_METHOD_TEXT_TRAFFIC,
65
    JK_LB_METHOD_TEXT_TRAFFIC,
66
    JK_LB_METHOD_TEXT_BUSYNESS,
66
    JK_LB_METHOD_TEXT_BUSYNESS,
67
    JK_LB_METHOD_TEXT_SESSIONS,
67
    JK_LB_METHOD_TEXT_SESSIONS,
68
    JK_LB_METHOD_TEXT_HASH,
68
    "unknown",
69
    "unknown",
69
    NULL
70
    NULL
70
};
71
};
Lines 185-190 Link Here
185
        return JK_LB_METHOD_BUSYNESS;
186
        return JK_LB_METHOD_BUSYNESS;
186
    else if  (*v == 's' || *v == 'S' || *v == '3')
187
    else if  (*v == 's' || *v == 'S' || *v == '3')
187
        return JK_LB_METHOD_SESSIONS;
188
        return JK_LB_METHOD_SESSIONS;
189
    else if  (*v == 'h' || *v == 'H' || *v == '4')
190
        return JK_LB_METHOD_HASH;
188
    else
191
    else
189
        return JK_LB_METHOD_DEF;
192
        return JK_LB_METHOD_DEF;
190
}
193
}
Lines 447-453 Link Here
447
                        ++id_start;
450
                        ++id_start;
448
                    if (*id_start == '=' && id_start[1]) {
451
                    if (*id_start == '=' && id_start[1]) {
449
                        /*
452
                        /*
450
                         * Session cookie was found, get it's value
453
                         * Session cookie was found, get its value
451
                         */
454
                         */
452
                        char *id_end;
455
                        char *id_end;
453
                        size_t sz;
456
                        size_t sz;
Lines 755-761 Link Here
755
    return candidate;
755
    return candidate;
756
}
756
}
757
757
758
unsigned long hash(char *str)
759
{
760
        unsigned long h = 0, g;
758
761
762
        while ( *str ) {
763
                h = ( h << 4 ) + *str++;
764
                if (( g = h & 0xF0000000 ))
765
                h ^= g >> 24;
766
                h &= ~g;
767
        }
768
769
        return h;
770
}
771
772
static int find_best_byhash(jk_ws_service_t *s,
773
                            lb_worker_t *p,
774
                            int *states,
775
                            jk_logger_t *l)
776
{
777
    unsigned long h;
778
    unsigned int i;
779
    char req[256];
780
781
    int candidate = -1;
782
    int activation;
783
    lb_sub_worker_t wr;
784
785
    strncpy(req, s->req_uri, 256);
786
    strncpy(req, s->query_string, 256);
787
788
    /* hash the request, return appropriate worker */
789
    h = hash(req);
790
    srand(h); //seed with hash
791
    i = rand() % p->num_of_workers;
792
793
    wr = p->lb_workers[i];
794
    activation = s->extension.activation ?
795
                 s->extension.activation[i] :
796
                 JK_LB_ACTIVATION_UNSET;
797
    if (activation == JK_LB_ACTIVATION_UNSET)
798
        activation = wr.activation;
799
800
    if (JK_WORKER_USABLE(states[wr.i], activation))
801
        candidate = i;
802
    return candidate;
803
}
804
805
759
static int find_best_byvalue(jk_ws_service_t *s,
806
static int find_best_byvalue(jk_ws_service_t *s,
760
                             lb_worker_t *p,
807
                             lb_worker_t *p,
761
                             int *states,
808
                             int *states,
Lines 888-894 Link Here
888
{
935
{
889
    int rc = -1;
936
    int rc = -1;
890
937
891
    rc = find_best_byvalue(s, p, states, l);
938
    /* Try byhash first, if enabled */
939
    if (p->lbmethod == JK_LB_METHOD_HASH)
940
      rc = find_best_byhash(s, p, states, l);
941
    /* If byhash didn't work (disabled, or error on hashed worker),
942
       fall back to default byvalue */
943
    if (rc < 0)
944
      rc = find_best_byvalue(s, p, states, l);
945
892
    /* By default use worker route as session route */
946
    /* By default use worker route as session route */
893
    if (rc < 0)
947
    if (rc < 0)
894
        rc = find_failover_worker(s, p, states, l);
948
        rc = find_failover_worker(s, p, states, l);
(-)tomcat-connectors/native/common/jk_lb_worker.h (-1 / +3 lines)
Lines 44-55 Link Here
44
#define JK_LB_METHOD_TRAFFIC           (1)
44
#define JK_LB_METHOD_TRAFFIC           (1)
45
#define JK_LB_METHOD_BUSYNESS          (2)
45
#define JK_LB_METHOD_BUSYNESS          (2)
46
#define JK_LB_METHOD_SESSIONS          (3)
46
#define JK_LB_METHOD_SESSIONS          (3)
47
#define JK_LB_METHOD_HASH              (4)
47
#define JK_LB_METHOD_DEF               (JK_LB_METHOD_REQUESTS)
48
#define JK_LB_METHOD_DEF               (JK_LB_METHOD_REQUESTS)
48
#define JK_LB_METHOD_MAX               (JK_LB_METHOD_SESSIONS)
49
#define JK_LB_METHOD_MAX               (JK_LB_METHOD_HASH)
49
#define JK_LB_METHOD_TEXT_REQUESTS     ("Request")
50
#define JK_LB_METHOD_TEXT_REQUESTS     ("Request")
50
#define JK_LB_METHOD_TEXT_TRAFFIC      ("Traffic")
51
#define JK_LB_METHOD_TEXT_TRAFFIC      ("Traffic")
51
#define JK_LB_METHOD_TEXT_BUSYNESS     ("Busyness")
52
#define JK_LB_METHOD_TEXT_BUSYNESS     ("Busyness")
52
#define JK_LB_METHOD_TEXT_SESSIONS     ("Sessions")
53
#define JK_LB_METHOD_TEXT_SESSIONS     ("Sessions")
54
#define JK_LB_METHOD_TEXT_HASH         ("Hash")
53
#define JK_LB_METHOD_TEXT_DEF          (JK_LB_METHOD_TEXT_REQUESTS)
55
#define JK_LB_METHOD_TEXT_DEF          (JK_LB_METHOD_TEXT_REQUESTS)
54
#define JK_LB_LOCK_OPTIMISTIC          (0)
56
#define JK_LB_LOCK_OPTIMISTIC          (0)
55
#define JK_LB_LOCK_PESSIMISTIC         (1)
57
#define JK_LB_LOCK_PESSIMISTIC         (1)

Return to bug 49822