Lab3 - оценка 5
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
global
|
||||
log stdout format raw local0 info
|
||||
maxconn 4096
|
||||
|
||||
resolvers docker
|
||||
nameserver dns 127.0.0.11:53
|
||||
resolve_retries 3
|
||||
timeout resolve 1s
|
||||
timeout retry 1s
|
||||
hold valid 2s
|
||||
hold obsolete 5s
|
||||
accepted_payload_size 8192
|
||||
|
||||
defaults
|
||||
mode http
|
||||
log global
|
||||
option httplog
|
||||
option dontlognull
|
||||
timeout connect 1s
|
||||
timeout client 30s
|
||||
timeout server 10s
|
||||
timeout http-request 5s
|
||||
timeout http-keep-alive 10s
|
||||
timeout check 500ms
|
||||
retries 2
|
||||
retry-on conn-failure
|
||||
option redispatch 1
|
||||
|
||||
frontend public
|
||||
bind :8080
|
||||
default_backend api
|
||||
|
||||
backend api
|
||||
balance roundrobin
|
||||
option httpchk GET /health/ready
|
||||
http-check expect status 200
|
||||
default-server check inter 1s fastinter 500ms downinter 1s fall 2 rise 2 init-addr none resolvers docker resolve-prefer ipv4
|
||||
server-template api 8 api:8080
|
||||
|
||||
frontend internal_stats
|
||||
bind :8404
|
||||
monitor-uri /healthz
|
||||
stats enable
|
||||
stats uri /stats
|
||||
stats refresh 5s
|
||||
@@ -0,0 +1,60 @@
|
||||
import http from 'k6/http';
|
||||
import encoding from 'k6/encoding';
|
||||
import { check } from 'k6';
|
||||
import { Counter } from 'k6/metrics';
|
||||
|
||||
const BASE = __ENV.BASE_URL || 'http://lb:8080';
|
||||
const USERS = parseInt(__ENV.USERS || '32');
|
||||
const RUN = __ENV.RUN_ID || String(Date.now());
|
||||
const non2xx = new Counter('non_2xx');
|
||||
|
||||
export const options = {
|
||||
scenarios: {
|
||||
main: {
|
||||
executor: 'constant-vus',
|
||||
vus: parseInt(__ENV.VUS || '64'),
|
||||
duration: __ENV.DURATION || '30s',
|
||||
},
|
||||
},
|
||||
setupTimeout: '120s',
|
||||
summaryTrendStats: ['avg', 'p(50)', 'p(95)', 'p(99)', 'max'],
|
||||
discardResponseBodies: false,
|
||||
};
|
||||
|
||||
export function setup() {
|
||||
const users = [];
|
||||
for (let i = 0; i < USERS; i++) {
|
||||
const username = `t1_${RUN}_${i}`.slice(0, 32);
|
||||
const password = `T3st-password-${RUN}-${i}`;
|
||||
let r = http.post(`${BASE}/api/v1/users`, JSON.stringify({ username, display_name: `Load ${i}`, password }),
|
||||
{ headers: { 'Content-Type': 'application/json' } });
|
||||
if (r.status !== 201) throw new Error(`create user: ${r.status}`);
|
||||
const id = r.json('id');
|
||||
r = http.post(`${BASE}/api/v1/auth/sessions`, null,
|
||||
{ headers: { Authorization: 'Basic ' + encoding.b64encode(`${username}:${password}`) } });
|
||||
if (r.status !== 201) throw new Error(`login: ${r.status}`);
|
||||
const token = r.json('token');
|
||||
r = http.post(`${BASE}/api/v1/chats`, JSON.stringify({ title: `load ${i}`, member_ids: [id] }),
|
||||
{ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` } });
|
||||
if (r.status !== 201) throw new Error(`create chat: ${r.status}`);
|
||||
users.push({ token, chat: r.json('id') });
|
||||
}
|
||||
return { users };
|
||||
}
|
||||
|
||||
export default function (data) {
|
||||
const u = data.users[(__VU - 1) % data.users.length];
|
||||
const auth = { Authorization: `Bearer ${u.token}` };
|
||||
let r;
|
||||
if (Math.random() < 0.7) {
|
||||
r = http.post(`${BASE}/api/v1/chats/${u.chat}/messages`,
|
||||
JSON.stringify({ text: `k6 ${__VU}-${__ITER}` }),
|
||||
{ headers: Object.assign({ 'Content-Type': 'application/json',
|
||||
'Idempotency-Key': `${RUN}-${__VU}-${__ITER}` }, auth), tags: { op: 'post' } });
|
||||
check(r, { 'post 201': (x) => x.status === 201 });
|
||||
} else {
|
||||
r = http.get(`${BASE}/api/v1/chats/${u.chat}/messages?limit=20`, { headers: auth, tags: { op: 'get' } });
|
||||
check(r, { 'get 200': (x) => x.status === 200 });
|
||||
}
|
||||
if (r.status < 200 || r.status >= 300) non2xx.add(1);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
bind 0.0.0.0
|
||||
port 6379
|
||||
protected-mode yes
|
||||
save ""
|
||||
appendonly no
|
||||
maxmemory 64mb
|
||||
maxmemory-policy volatile-ttl
|
||||
include /run/secrets/valkey_auth
|
||||
Reference in New Issue
Block a user