k6 - 02를 사용한 성능 테스트 - 여러 작업
이를 위해 테스트할 실제 앱이 있는 것이 좋습니다. 간단하고 익숙하기 때문에 파일 호스팅 및 공유ownCloud를 선택했습니다.
Dropbox와 유사한 솔루션입니다.
테스트용 ownCloud 인스턴스를 시작하고 실행하는 가장 쉬운 방법은 docker를 사용하는 것입니다.
그냥 실행하십시오:
docker run -p 8080:8080 --name owncloud owncloud/server .이 마법의
docker run 명령은 http://localhost:8080에서 연결할 수 있는 새로운 ownCloud 설치를 제공해야 합니다.매우 안전한 암호
admin가 있는 admin라는 사용자 사전 설정이 하나 있습니다. UI에 로그인하여 파일 업로드, 새 사용자 생성, 파일 및 폴더 공유 등을 할 수 있습니다.ownCloud 자체를 조금 사용해 본 후 k6으로 돌아가 보겠습니다.
파일 생성 테스트
파일(
script.js )을 만들고 다음 내용을 추가합니다.import http from 'k6/http'
import encoding from 'k6/encoding'
import { check } from 'k6'
import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.0.0/index.js'
export let options = {
iterations: 100,
vus: 10
}
export default function() {
const fileName = `${uuidv4()}.txt`
const url = `http://localhost:8080/remote.php/webdav/${fileName}`
const body = 'some content'
const headers = {
'Authorization': 'Basic ' + encoding.b64encode('admin:admin'),
'Content-Type': 'application/x-www-form-urlencoded'
}
const response = http.request('PUT', url, body, { headers: headers })
check(response, {
'status is 201': (r) => r.status === 201 || 204
})
}
options 개체에서 iterations: 100 및 vus: 10 즉, 100개의 테스트 실행이 10 vus로 나뉩니다. iterations를 vus로 나누는 방법을 지정하기 위해 executor 옵션을 제공할 수 있습니다. 실행자에 대한 자세한 내용은 확인https://k6.io/docs/using-k6/scenarios/executors/PUT 요청을 전송하고 있습니다. 인증 헤더의 경우 우리가 만든 비밀번호admin와 함께 사용자admin를 사용하고 있습니다. 따라서 기본적으로 옵션의 10 vus는 admin 사용자 인증fileName에서 uuid을 사용하고 있습니다. 테스트 삭제 파일
import http from 'k6/http'
import encoding from 'k6/encoding'
import { check } from 'k6'
import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.0.0/index.js'
export let options = {
iterations: 100,
vus: 10
}
const createFile = url => {
const body = 'some content'
const headers = {
'Authorization': 'Basic ' + encoding.b64encode('admin:admin'),
'Content-Type': 'application/x-www-form-urlencoded'
}
const response = http.request('PUT', url, body, { headers: headers })
check(response, {
'status is 201': (r) => r.status === 201 || 204
})
}
const deleteFile = (url) => {
const headers = {
'Authorization': 'Basic ' + encoding.b64encode('admin:admin')
}
const response = http.request('DELETE', url, undefined, { headers: headers })
check(response, {
'status is 204': (r) => r.status === 204
})
}
export default function() {
const fileName = `${uuidv4()}.txt`
const url = `http://localhost:8080/remote.php/webdav/${fileName}`
createFile(url)
deleteFile(url)
}
여기에 파일을 삭제하는 코드를 추가하고 있습니다. 또한 파일 생성 및 삭제에 대한 논리를 두 개의 별도 함수
createFile 및 deleteFile로 분리했습니다.설정 단계
테스트 중에
stages를 사용하여 VU 레벨을 올리거나 내릴 수 있습니다. options.stages 속성을 사용하면 램핑 동작을 구성할 수 있습니다....
export let options = {
stages: [
{ duration: '30s', target: 20 },
{ duration: '1m30s', target: 10 },
{ duration: '20s', target: 0 }
]
}
...
이제
k6 run script.js를 사용하여 테스트를 실행하면 다음과 같습니다.
위의 스크린샷에서 볼 수 있듯이 테스트는
2m20s (30s + 1m30s + 20s)의 총 지속 시간 동안 실행되며 vus max는 20(첫 번째 단계의 끝)이고 min는 1입니다. ) 첫 번째 단계가 시작될 때 발생합니다.
Reference
이 문제에 관하여(k6 - 02를 사용한 성능 테스트 - 여러 작업), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/jankaritech/performance-testing-with-k6-02-multiple-tasks-2im1텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)