Created
April 3, 2025 01:45
-
-
Save neuwcodebox/729bd3871a4c4972c7082c30c0cc03df to your computer and use it in GitHub Desktop.
Embedding API Benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const URL = 'http://localhost:7003/embed/'; | |
| const PAYLOAD = JSON.stringify({ sentences: ['Hello World!'] }); | |
| const HEADERS = { 'Content-Type': 'application/json' }; | |
| const CONCURRENT_REQUESTS = 10; // 동시 요청 개수 | |
| const TOTAL_REQUESTS = 100; // 총 요청 개수 | |
| async function measureLatency() { | |
| let times = []; | |
| for (let i = 0; i < TOTAL_REQUESTS; i++) { | |
| let start = performance.now(); | |
| await fetch(URL, { method: 'POST', headers: HEADERS, body: PAYLOAD }); | |
| let end = performance.now(); | |
| times.push(end - start); | |
| } | |
| let avgTime = times.reduce((a, b) => a + b, 0) / times.length; | |
| console.log(`평균 응답 시간: ${avgTime.toFixed(2)}ms`); | |
| } | |
| async function measureThroughput() { | |
| let promises = []; | |
| let completed = 0; | |
| let start = performance.now(); | |
| for (let i = 0; i < TOTAL_REQUESTS; i++) { | |
| if (promises.length >= CONCURRENT_REQUESTS) { | |
| await Promise.race(promises); | |
| promises = promises.filter(p => p !== null); | |
| } | |
| let p = fetch(URL, { method: 'POST', headers: HEADERS, body: PAYLOAD }).then(() => completed++); | |
| promises.push(p); | |
| } | |
| await Promise.all(promises); | |
| let end = performance.now(); | |
| let throughput = (completed / ((end - start) / 1000)).toFixed(2); | |
| console.log(`초당 처리량: ${throughput} requests/sec`); | |
| } | |
| measureLatency().then(() => measureThroughput()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment