From b262e7656376a938fc149ae1bf280eeef81c6002 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 3 Jun 2009 13:52:03 -0400 Subject: Fix gprof bottlenecks on exit nodes found by Jacob. Apparently all the stuff that does a linear scan over all the DNS cache entries can get really expensive when your DNS cache is very large. It's hard to say how much this will help performance, since gprof doesn't count time spent in OpenSSL or zlib, but I'd guess 10%. Also, this patch removes calls to assert_connection_ok() from inside the read and write callbacks, which are similarly unneeded, and a little costlier than I'm happy with. This is probably worth backporting to 0.2.0. --- src/or/dns.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/or/dns.c') diff --git a/src/or/dns.c b/src/or/dns.c index ad5b5de405..74852b0f70 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -736,15 +736,25 @@ void assert_connection_edge_not_dns_pending(edge_connection_t *conn) { pending_connection_t *pend; - cached_resolve_t **resolve; + cached_resolve_t search; +#if 1 + cached_resolve_t *resolve; + strlcpy(search.address, conn->_base.address, sizeof(search.address)); + resolve = HT_FIND(cache_map, &cache_root, &search); + if (!resolve) + return; + for (pend = resolve->pending_connections; pend; pend = pend->next) { + tor_assert(pend->conn != conn); + } +#else + cached_resolve_t **resolve; HT_FOREACH(resolve, cache_map, &cache_root) { - for (pend = (*resolve)->pending_connections; - pend; - pend = pend->next) { + for (pend = (*resolve)->pending_connections; pend; pend = pend->next) { tor_assert(pend->conn != conn); } } +#endif } /** Log an error and abort if any connection waiting for a DNS resolve is -- cgit v1.2.3-54-g00ecf