2016-03-23 17 views
0

varnish vmod_directors啓用後端負載平衡在不同的模式:round_robin,fallback,random和HASH。首先明確了Varnish如何處理病態後端。當後端生病時,Varnish hash director如何處理密鑰分發?

但是,在HASH導演中會發生什麼?它會重新分配所有的關鍵空間?或者只有1/N個鍵會被移位(N是後端的數量)?

或者,您可能決定將後端分組爲2對來實現HA並且不重複緩存? (董事可以使用其他董事作爲後端)

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 
相關問題