Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 62d24fb

Browse files
committed
Only rewrite an image once even if it's requested via ipro many times
concurrently. Print elapsed time properly for subshell tests. Fix typo in SVG reference which was causing spurious timeout warnings in nginx tests, and then flagged by nginx system tests. Remove nginx test flakiness by using fetch_until an image gets small to indicate an ipro-rewrite is done, rather than testing for image_ongoing_rewrites to be zero. The old technique might fail because we might check that stat before the image starts being rewritten. Note: with this change, nginx system tests no longer flake for me, whereas previously about 10% of the time it would flake on "IPRO flow uses cache as expected". That was also suppressed for valgrind runs, which is no longer needed. Even after this change, nginx system tests with valgrind tests still flake with "Fetch timed out" log messages, which I am adding to the suppressions, and with "Embed image configuration in rewritten image URL.", where the recursive-wget result is not optimized. I think that might be a real user-facing bug, and I will report it to the nginx list.
1 parent 83c9607 commit 62d24fb

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

install/mod_pagespeed_test/webp_rewriting/unresizable_images.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
</style>
1313
<body>
14-
<img src="../../mod_pagespeed_example/images/Cschedule_event.svg"
14+
<img src="../../mod_pagespeed_example/images/schedule_event.svg"
1515
width="20" height="10"
1616
title="SVG image won't be resized nor rewritten."/><br/>
1717
<img src="../../mod_pagespeed_example/images/gray_saved_as_rgb.webp"

net/instaweb/rewriter/rewrite_context.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,7 @@ void RewriteContext::CallLockFailed() {
17081708
void RewriteContext::LockFailed() {
17091709
num_rewrites_abandoned_for_lock_contention_->Add(1);
17101710
MarkTooBusy();
1711-
Activate();
1711+
Finalize();
17121712
}
17131713

17141714
bool RewriteContext::IsDistributedRewriteForHtml() const {

pagespeed/automatic/system_test_helpers.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ function run_test() {
237237
else
238238
# Use a subshell to keep modifications tests make to the test environment
239239
# from interfering with eachother.
240-
(source "$this_dir/system_tests/${test_name}.sh")
240+
(source "$this_dir/system_tests/${test_name}.sh"; update_elapsed_time)
241+
previous_time_ms=0
241242
fi
242243
}
243244

@@ -541,28 +542,33 @@ function get_stat() {
541542
}
542543

543544
function check_stat() {
545+
check_stat_op $1 $2 $3 $4 =
546+
}
547+
548+
function check_stat_op() {
544549
if [ "${statistics_enabled:-1}" -eq "0" ]; then
545550
return
546551
fi
547552
local OLD_STATS_FILE=$1
548553
local NEW_STATS_FILE=$2
549554
local COUNTER_NAME=$3
550555
local EXPECTED_DIFF=$4
556+
local OP=$5
551557
local OLD_VAL=$(get_stat ${COUNTER_NAME} <${OLD_STATS_FILE})
552558
local NEW_VAL=$(get_stat ${COUNTER_NAME} <${NEW_STATS_FILE})
553559

554560
# This extra check is necessary because the syntax error in the second if
555561
# does not cause bash to fail :/
556562
if [ "${NEW_VAL}" != "" -a "${OLD_VAL}" != "" ]; then
557-
if [ $((${NEW_VAL} - ${OLD_VAL})) = ${EXPECTED_DIFF} ]; then
563+
if [ $((${NEW_VAL} - ${OLD_VAL})) $OP ${EXPECTED_DIFF} ]; then
558564
return;
559565
fi
560566
fi
561567

562568
# Failure
563569
local EXPECTED_VAL=$((${OLD_VAL} + ${EXPECTED_DIFF}))
564570
echo -n "Mismatched counter value : ${COUNTER_NAME} : "
565-
echo "Expected=${EXPECTED_VAL} Actual=${NEW_VAL}"
571+
echo "Expected(${EXPECTED_VAL}) $OP Actual(${NEW_VAL})"
566572
echo "Compare stat files ${OLD_STATS_FILE} and ${NEW_STATS_FILE}"
567573
handle_failure
568574
}

pagespeed/system/system_test.sh

+18-6
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,19 @@ if [ $statistics_enabled = "1" ]; then
527527
check [ $not_cacheable = $((not_cacheable_start + 1)) ]
528528
URL=""
529529
AUTH=""
530+
531+
start_test A burst of image requests should yield only one rewrite.
532+
URL="$EXAMPLE_ROOT/images/Puzzle.jpg?a=$RANDOM"
533+
start_image_rewrites=$(scrape_stat image_rewrites)
534+
echo Running burst of 20x: \"wget -q -O - $URL '|' wc -c\"
535+
for ((i = 0; i < 20; ++i)); do
536+
echo -n $(wget -q -O - $URL | wc -c) ""
537+
done
538+
echo "... done"
539+
sleep 1
540+
end_image_rewrites=$(scrape_stat image_rewrites)
541+
check [ $end_image_rewrites = $((start_image_rewrites + 1)) ]
542+
URL=""
530543
fi
531544

532545
if [ "$SECONDARY_HOSTNAME" != "" ]; then
@@ -1108,15 +1121,14 @@ if [ "$SECONDARY_HOSTNAME" != "" ]; then
11081121
check_stat $STATS.0 $STATS.1 image_rewrites 0
11091122

11101123
# Second IPRO request.
1111-
http_proxy=$SECONDARY_HOSTNAME check $WGET_DUMP $URL -O /dev/null
1112-
# Wait for image rewrite to finish.
1113-
http_proxy=$SECONDARY_HOSTNAME fetch_until "$IPRO_STATS_URL" \
1114-
'get_stat image_ongoing_rewrites' 0
1124+
# Original file has content-length 15131. Once ipro-optimized, it is
1125+
# 11395, so fetch it until it's less than 12000.
1126+
http_proxy=$SECONDARY_HOSTNAME fetch_until $URL "wc -c" 12000 "" "-lt"
11151127
http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP $IPRO_STATS_URL > $STATS.2
11161128

11171129
# Resource is found in cache the second time.
1118-
check_stat $STATS.1 $STATS.2 cache_hits 1
1119-
check_stat $STATS.1 $STATS.2 ipro_served 1
1130+
check_stat_op $STATS.1 $STATS.2 cache_hits 1 -ge
1131+
check_stat_op $STATS.1 $STATS.2 ipro_served 1 -ge
11201132
check_stat $STATS.1 $STATS.2 ipro_not_rewritable 0
11211133
# So we don't run the ipro recorder flow.
11221134
check_stat $STATS.1 $STATS.2 ipro_not_in_cache 0

0 commit comments

Comments
 (0)