Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orbea
Tor
Commits
7740a8b5
Commit
7740a8b5
authored
4 years ago
by
George Kadianakis
Browse files
Options
Downloads
Patches
Plain Diff
Rate-limit counter should increase once per minute.
parent
e6885802
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/feature/stats/rephist.c
+15
-4
15 additions, 4 deletions
src/feature/stats/rephist.c
src/test/test_stats.c
+39
-0
39 additions, 0 deletions
src/test/test_stats.c
with
54 additions
and
4 deletions
src/feature/stats/rephist.c
+
15
−
4
View file @
7740a8b5
...
...
@@ -280,18 +280,29 @@ STMT_END
void
rep_hist_note_overload
(
overload_type_t
overload
)
{
static
time_t
last_read_counted
=
0
;
static
time_t
last_write_counted
=
0
;
switch
(
overload
)
{
case
OVERLOAD_GENERAL
:
SET_TO_START_OF_HOUR
(
overload_stats
.
overload_general_time
);
break
;
case
OVERLOAD_READ
:
case
OVERLOAD_READ
:
{
SET_TO_START_OF_HOUR
(
overload_stats
.
overload_ratelimits_time
);
overload_stats
.
overload_read_count
++
;
if
(
approx_time
()
>=
last_read_counted
+
60
)
{
/* Count once a minute */
overload_stats
.
overload_read_count
++
;
last_read_counted
=
approx_time
();
}
break
;
case
OVERLOAD_WRITE
:
}
case
OVERLOAD_WRITE
:
{
SET_TO_START_OF_HOUR
(
overload_stats
.
overload_ratelimits_time
);
overload_stats
.
overload_write_count
++
;
if
(
approx_time
()
>=
last_write_counted
+
60
)
{
/* Count once a minute */
overload_stats
.
overload_write_count
++
;
last_write_counted
=
approx_time
();
}
break
;
}
case
OVERLOAD_FD_EXHAUSTED
:
SET_TO_START_OF_HOUR
(
overload_stats
.
overload_fd_exhausted_time
);
overload_stats
.
overload_fd_exhausted
++
;
...
...
This diff is collapsed.
Click to expand it.
src/test/test_stats.c
+
39
−
0
View file @
7740a8b5
...
...
@@ -807,6 +807,45 @@ test_overload_stats(void *arg)
stats_str
=
rep_hist_get_overload_stats_lines
();
tt_assert
(
!
stats_str
);
/* Now test the rate-limit rate-limiter ;) */
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
rep_hist_note_overload
(
OVERLOAD_READ
);
}
/* We already have an event registered from the previous tests. We just
* registered ten more overload events, but only one should have been counted
* because of the rate limiter */
stats_str
=
rep_hist_get_overload_stats_lines
();
tt_str_op
(
"overload-ratelimits 1 2002-01-10 02:00:00 1000 2000 2 0"
,
OP_EQ
,
stats_str
);
tor_free
(
stats_str
);
/* Increment time by 59 secs and try again. No additional events should
register */
current_time
+=
59
;
update_approx_time
(
current_time
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
rep_hist_note_overload
(
OVERLOAD_READ
);
}
stats_str
=
rep_hist_get_overload_stats_lines
();
tt_str_op
(
"overload-ratelimits 1 2002-01-10 02:00:00 1000 2000 2 0"
,
OP_EQ
,
stats_str
);
tor_free
(
stats_str
);
/* Now increment time by 2 secs -- taking it after the minute rate limiting
and see that events will register again */
current_time
+=
2
;
update_approx_time
(
current_time
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
rep_hist_note_overload
(
OVERLOAD_READ
);
rep_hist_note_overload
(
OVERLOAD_WRITE
);
}
stats_str
=
rep_hist_get_overload_stats_lines
();
tt_str_op
(
"overload-ratelimits 1 2002-01-10 02:00:00 1000 2000 3 1"
,
OP_EQ
,
stats_str
);
tor_free
(
stats_str
);
done:
tor_free
(
stats_str
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment