2016-03-23 8 views
0

Varnish vmod_directorsは、round_robin、fallback、random、およびHASHの各モードでバックエンドロードバランシングを有効にします。最初のものについては、ワニスが病気のバックエンドをどのように処理するのかは明らかです。バックエンドが病気になったとき、ワニスディレクターがキー配布をどのように処理しますか?

しかし、HASHディレクターではどうなりますか?すべてのキースペースを再配布しますか?または、1/Nキーのみがシフトされます(Nはバックエンドの数です)。

または、HAを実現するために2ペアでバックエンドをグループ化し、キャッシュを複製しないことを決定しましたか?私は本当に起こるとワニスは、現在の健康バックエンドのすべてのキーを再配布するかを確認するワニスのテストを行った

sub vcl_init { 
    new h = directors.hash(); 
    h.add_backend(backend_1, 1); 
    h.add_backend(backend_2, 1); // <------ sick 
    h.add_backend(backend_3, 1); 
    h.add_backend(backend_4, 1); 
    h.add_backend(backend_5, 1); 
    h.add_backend(backend_6, 1); 
} 

sub vcl_recv { 
    // pick a backend based on the request URL 
    set req.backend_hint = h.backend(req.url); 
} 

VS

new main_hash_director = directors.hash(); 
h.add_backend(hash_director_A, 1); 
h.add_backend(hash_director_B, 1); 
h.add_backend(hash_director_C, 1); 


new hash_director_A = directors.hash(); 
h.add_backend(backend_1, 1); 
h.add_backend(backend_2, 1); // <------ sick 

new hash_director_B = directors.hash(); 
h.add_backend(backend_3, 1); 
h.add_backend(backend_4, 1); 

new hash_director_C = directors.hash(); 
h.add_backend(backend_5, 1); 
h.add_backend(backend_6, 1); 

答えて

0

(取締役は、バックエンドとして、他の取締役を使用することができます)。

VMODは一貫したハッシングのために利用可能があります:https://www.varnish-cache.org/vmod/vslp-stateless-persistence-consistent-hashing-director-vmod

varnishtest "ハッシュディレクター"

server s1 { 
    rxreq 
    txresp -hdr "Foo: 1" 
    rxreq 
    txresp -hdr "Foo: 1" 
    rxreq 
    txresp -hdr "Foo: 1" 
    rxreq 
    txresp -hdr "Foo: 1" 

} -start 

server s2 { 
    rxreq 
    txresp -hdr "Foo: 2" 
    rxreq 
    txresp -hdr "Foo: 2" 
    rxreq 
    txresp -hdr "Foo: 2" 
    rxreq 
    txresp -hdr "Foo: 2" 
} -start 

server s3 { 
    rxreq 
    txresp -hdr "Foo: 3" 
    rxreq 
    txresp -hdr "Foo: 3" 
    rxreq 
    txresp -hdr "Foo: 3" 
    rxreq 
    txresp -hdr "Foo: 3" 
} -start 

server s4 { 
    rxreq 
    txresp -hdr "Foo: 4" 
    rxreq 
    txresp -hdr "Foo: 4" 
    rxreq 
    txresp -hdr "Foo: 4" 
    rxreq 
    txresp -hdr "Foo: 4" 
} -start 

server s5 { 
    rxreq 
    txresp -hdr "Foo: 5" 
    rxreq 
    txresp -hdr "Foo: 5" 
    rxreq 
    txresp -hdr "Foo: 5" 
    rxreq 
    txresp -hdr "Foo: 5" 
} -start 

server s6 { 
    rxreq 
    txresp -hdr "Foo: 6" 
    rxreq 
    txresp -hdr "Foo: 6" 
    rxreq 
    txresp -hdr "Foo: 6" 
    rxreq 
    txresp -hdr "Foo: 6" 
} -start 

server s7 { 
    rxreq 
    txresp -hdr "Foo: 7" 
    rxreq 
    txresp -hdr "Foo: 7" 
    rxreq 
    txresp -hdr "Foo: 7" 
    rxreq 
    txresp -hdr "Foo: 7" 
} -start 

server s8 { 
    rxreq 
    txresp -hdr "Foo: 8" 
    rxreq 
    txresp -hdr "Foo: 8" 
    rxreq 
    txresp -hdr "Foo: 8" 
    rxreq 
    txresp -hdr "Foo: 8" 
} -start 

server s9 { 
    rxreq 
    txresp -hdr "Foo: 9" 
    rxreq 
    txresp -hdr "Foo: 9" 
    rxreq 
    txresp -hdr "Foo: 9" 
    rxreq 
    txresp -hdr "Foo: 9" 
} -start 

server s10 { 
    rxreq 
    txresp -hdr "Foo: 10" 
    rxreq 
    txresp -hdr "Foo: 10" 
    rxreq 
    txresp -hdr "Foo: 10" 
    rxreq 
    txresp -hdr "Foo: 10" 
} -start 

varnish v1 -vcl+backend { 
    director h1 hash { 
    { .backend = s1; .weight = 1; } 
    { .backend = s2; .weight = 1; } 
    { .backend = s3; .weight = 1; } 
    { .backend = s4; .weight = 1; } 
    { .backend = s5; .weight = 1; } 
    { .backend = s6; .weight = 1; } 
    { .backend = s7; .weight = 1; } 
    { .backend = s8; .weight = 1; } 
    { .backend = s9; .weight = 1; } 
    { .backend = s10; .weight = 1; } 
    } 

    sub vcl_recv { 
    set req.backend = h1; 
    return(pass); 
    } 

} -start 

# first run----------------------------- 
client c1 { 

    txreq -url /12 
    rxresp 
    expect resp.http.foo == "1" 

    txreq -url /14 
    rxresp 
    expect resp.http.foo == "4" 

    txreq -url /45 
    rxresp 
    expect resp.http.foo == "7" 


    txreq -url /65 
    rxresp 
    expect resp.http.foo == "5" 

    txreq -url /78 
    rxresp 
    expect resp.http.foo == "9" 


    txreq -url /894 
    rxresp 
    expect resp.http.foo == "8" 

txreq -url /115 
rxresp 
expect resp.http.foo == "2" 

    txreq -url /321341 
    rxresp 
    expect resp.http.foo == "6" 

    txreq -url /612 
    rxresp 
    expect resp.http.foo == "10" 

    txreq -url /33 
    rxresp 
    expect resp.http.foo == "3" 

} -run 

varnish v1 -cliok "backend.set_health s1 sick" 
# second run----------------------------- 
client c1 { 

    txreq -url /12 
    rxresp 
# expect resp.http.foo == "1" FAIL 

    txreq -url /14 
    rxresp 
    expect resp.http.foo == "4" 

    txreq -url /45 
    rxresp 
# expect resp.http.foo == "7" FAIL 


    txreq -url /65 
    rxresp 
    expect resp.http.foo == "5" 

    txreq -url /78 
    rxresp 
# expect resp.http.foo == "9" FAIL 


    txreq -url /894 
    rxresp 
    expect resp.http.foo == "8" 

txreq -url /115 
rxresp 
expect resp.http.foo == "2" 

    txreq -url /321341 
    rxresp 
    expect resp.http.foo == "6" 

    txreq -url /612 
    rxresp 
# expect resp.http.foo == "10" FAIL 

    txreq -url /33 
    rxresp 
    expect resp.http.foo == "3" 

} -run