forked from pollinations/pollinations
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parallel_images.sh
More file actions
executable file
·84 lines (68 loc) · 2.73 KB
/
test_parallel_images.sh
File metadata and controls
executable file
·84 lines (68 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Parallel image generation test script
echo "Starting parallel image generation test at $(date)"
echo "=========================================="
# Base URL components - LOCAL SERVER
BASE_URL="http://localhost:16384/prompt"
COMMON_PARAMS="nologo=true&model=seedream&image=https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F86964862%3Fv%3D4,https%3A%2F%2Fimages.squarespace-cdn.com%2Fcontent%2Fv1%2F5c5554d316b64061c6f8a20d%2F1596136490907-06FHBY3TVORRAY0OTO43%2F4b86861cdbbe3576e8c003fccae2c372.jpg&referrer=ppp"
# Function to make a single request with timing
make_request() {
local num=$1
local seed=$((19510 + num - 1))
local random_hash=$(openssl rand -hex 8)
local prompt="${random_hash}%20${num}%20many%20instances%20of%20the%20the%20logo%20tessellated%20in%20mc%20escher%20hand%20drawn%20style.%20no%20birds"
local url="${BASE_URL}/${prompt}?seed=${seed}&${COMMON_PARAMS}"
local output_file="/tmp/image${num}.jpg"
echo "Request ${num}: Starting at $(date '+%H:%M:%S.%3N') with hash: ${random_hash}"
local start_time=$(date +%s.%3N)
curl -s -w "Request ${num}: HTTP %{http_code}, Total time: %{time_total}s, Size: %{size_download} bytes\n" \
-o "${output_file}" \
"${url}"
local end_time=$(date +%s.%3N)
local duration=$(echo "$end_time - $start_time" | bc -l)
echo "Request ${num}: Finished at $(date '+%H:%M:%S.%3N') (Duration: ${duration}s)"
# Check if file was created and has content
if [ -f "${output_file}" ] && [ -s "${output_file}" ]; then
# Use macOS stat syntax (-f%z instead of -c%s)
local file_size=$(stat -f%z "${output_file}")
echo "Request ${num}: File saved successfully (${file_size} bytes)"
else
echo "Request ${num}: ERROR - File not created or empty"
fi
echo "Request ${num}: ----------------------------------------"
}
# Record overall start time
OVERALL_START=$(date +%s.%3N)
echo "Overall start time: $(date '+%H:%M:%S.%3N')"
echo ""
# Launch all requests in parallel
make_request 1 &
PID1=$!
make_request 2 &
PID2=$!
make_request 3 &
PID3=$!
# Wait for all to complete
echo "Waiting for all requests to complete..."
wait $PID1
wait $PID2
wait $PID3
# Calculate overall duration
OVERALL_END=$(date +%s.%3N)
OVERALL_DURATION=$(echo "$OVERALL_END - $OVERALL_START" | bc -l)
echo ""
echo "=========================================="
echo "All requests completed at $(date '+%H:%M:%S.%3N')"
echo "Total wall-clock time: ${OVERALL_DURATION}s"
echo ""
# Show file information
echo "Generated files:"
for i in 1 2 3; do
if [ -f "/tmp/image${i}.jpg" ]; then
ls -lh "/tmp/image${i}.jpg"
else
echo "image${i}.jpg: NOT FOUND"
fi
done
echo ""
echo "Test completed at $(date)"