[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Streamline the two redundant "Has the second rolled over?" ...
- To: or-cvs@freehaven.net
- Subject: [or-cvs] Streamline the two redundant "Has the second rolled over?" ...
- From: nickm@seul.org (Nick Mathewson)
- Date: Wed, 3 Nov 2004 11:38:07 -0500 (EST)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Wed, 03 Nov 2004 11:38:28 -0500
- Reply-to: or-dev@freehaven.net
- Sender: owner-or-cvs@freehaven.net
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv8506/src/or
Modified Files:
connection.c main.c
Log Message:
Streamline the two redundant "Has the second rolled over?" checks in prepare_for_poll and connection_bucket_refill; also, generate BANDWIDTH control events
Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.277
retrieving revision 1.278
diff -u -d -r1.277 -r1.278
--- connection.c 3 Nov 2004 10:18:31 -0000 1.277
+++ connection.c 3 Nov 2004 16:38:04 -0000 1.278
@@ -695,29 +695,19 @@
}
}
-/** Keep a timeval to know when time has passed enough to refill buckets */
-static struct timeval current_time;
-
/** Initiatialize the global read bucket to options.BandwidthBurst,
* and current_time to the current time. */
void connection_bucket_init(void) {
- tor_gettimeofday(¤t_time);
global_read_bucket = options.BandwidthBurst; /* start it at max traffic */
global_write_bucket = options.BandwidthBurst; /* start it at max traffic */
}
-/** Some time has passed; increment buckets appropriately. */
+/** A second has rolled over; increment buckets appropriately. */
void connection_bucket_refill(struct timeval *now) {
int i, n;
connection_t *conn;
connection_t **carray;
- if(now->tv_sec <= current_time.tv_sec)
- return; /* wait until the second has rolled over */
-
- current_time.tv_sec = now->tv_sec; /* update current_time */
- /* (ignore usecs for now) */
-
/* refill the global buckets */
if(global_read_bucket < options.BandwidthBurst) {
global_read_bucket += options.BandwidthRate;
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.349
retrieving revision 1.350
diff -u -d -r1.349 -r1.350
--- main.c 3 Nov 2004 01:31:42 -0000 1.349
+++ main.c 3 Nov 2004 16:38:04 -0000 1.350
@@ -1,4 +1,4 @@
-/* Copyright 2001,2002,2003 Roger Dingledine, Matej Pfajfar. */
+/* Copyright 2001,2002,2003,2004 Roger Dingledine, Matej Pfajfar. */
/* See LICENSE for licensing information */
/* $Id$ */
@@ -897,21 +897,25 @@
tor_gettimeofday(&now);
- /* Check how much bandwidth we've consumed, and increment the token
- * buckets. */
- stats_n_bytes_read += stats_prev_global_read_bucket - global_read_bucket;
- stats_n_bytes_read_in_interval += stats_prev_global_read_bucket - global_read_bucket;
- stats_n_bytes_written += stats_prev_global_write_bucket - global_write_bucket;
- stats_n_bytes_written_in_interval += stats_prev_global_write_bucket - global_write_bucket;
-
- connection_bucket_refill(&now);
- stats_prev_global_read_bucket = global_read_bucket;
- stats_prev_global_write_bucket = global_write_bucket;
+ if(now.tv_sec > current_second) {
+ /* the second has rolled over. check more stuff. */
+ size_t bytes_written;
+ size_t bytes_read;
+ bytes_written = stats_prev_global_write_bucket - global_write_bucket;
+ bytes_read = stats_prev_global_read_bucket - global_read_bucket;
+ stats_n_bytes_read += bytes_read;
+ stats_n_bytes_read_in_interval += bytes_read;
+ stats_n_bytes_written += bytes_written;
+ stats_n_bytes_written_in_interval += bytes_written;
+ control_event_bandwidth_used((uint32_t)bytes_read,(uint32_t)bytes_written);
- if(now.tv_sec > current_second) { /* the second has rolled over. check more stuff. */
+ connection_bucket_refill(&now);
+ stats_prev_global_read_bucket = global_read_bucket;
+ stats_prev_global_write_bucket = global_write_bucket;
if(current_second)
stats_n_seconds_uptime += (now.tv_sec - current_second);
+
assert_all_pending_dns_resolves_ok();
run_scheduled_events(now.tv_sec);
assert_all_pending_dns_resolves_ok();
@@ -1242,11 +1246,11 @@
if (stats_n_seconds_uptime)
log(severity,
- "Average bandwidth used: "U64_FORMAT"/%ld = %d bytes/sec",
+ "Average bandwidth used: "U64_FORMAT"/%ld = %d bytes/sec",
U64_PRINTF_ARG(stats_n_bytes_read),
stats_n_seconds_uptime,
(int) (stats_n_bytes_read/stats_n_seconds_uptime));
-
+
rep_hist_dump_stats(now,severity);
rend_service_dump_stats(severity);
}