<commit_before>#!/usr/bin/env python
# Copyright 2009 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


"""Simple DNS server comparison benchmarking tool.

Designed to assist system administrators in selection and prioritization.
"""

__author__ = '<EMAIL> (<NAME>)'

import datetime
import optparse
import sys
import tempfile
# Make it easy to import 3rd party utilities without editing their imports.
sys.path.append('lib/third_party')
from lib import benchmark
from lib import config
from lib import history_parser
from lib import nameserver_list
from lib import util

VERSION = '0.8.3'
EXPECTED_CONGESTION_DURATION = 45

def DetermineCongestionFactor():
  (intercepted, i_duration) = util.AreDNSPacketsIntercepted()
  if intercepted:
    print 'XXX[ OHNO! ]XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
    print 'XX Someone upstream of this machine is doing evil things and  XX'
    print 'XX intercepting all outgoing nameserver requests. The results XX'
    print 'XX of this program will be useless. Get your ISP to fix it.   XX'
    print 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
    print ''
    sys.exit(1)

  g_duration = util.CongestionCheck()
  duration = util.CalculateListAverage((i_duration, g_duration))
  congestion = duration / EXPECTED_DURATION
  print 'congestion duration: %s' % duration
  if duration > EXPECTED_CONGESTION_DURATION:
    print '* Queries are running %.1fX slower than expected, increasing timeouts.' % congestion
    return congestion
  else:
    return 1

# Detect congestion problems early!
EXPECTED_DURATION = 75<commit_msg>Fix congestion calculation<commit_after>#!/usr/bin/env python
# Copyright 2009 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


"""Simple DNS server comparison benchmarking tool.

Designed to assist system administrators in selection and prioritization.
"""

__author__ = '<EMAIL> (<NAME>)'

import datetime
import optparse
import sys
import tempfile
# Make it easy to import 3rd party utilities without editing their imports.
sys.path.append('lib/third_party')
from lib import benchmark
from lib import config
from lib import history_parser
from lib import nameserver_list
from lib import util

VERSION = '0.8.3'
EXPECTED_CONGESTION_DURATION = 45

def DetermineCongestionFactor():
  (intercepted, i_duration) = util.AreDNSPacketsIntercepted()
  if intercepted:
    print 'XXX[ OHNO! ]XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
    print 'XX Someone upstream of this machine is doing evil things and  XX'
    print 'XX intercepting all outgoing nameserver requests. The results XX'
    print 'XX of this program will be useless. Get your ISP to fix it.   XX'
    print 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
    print ''
    sys.exit(1)

  g_duration = util.CongestionCheck()
  duration = util.CalculateListAverage((i_duration, g_duration))
  congestion = EXPECTED_DURATION / duration
  print '- Intercept query took %sms, Congestion query took %sms' % (i_duration, g_duration)
  if duration > EXPECTED_CONGESTION_DURATION:
    print '- Queries are running %.1fX slower than expected, increasing timeouts.' % congestion
    return congestion
  else:
    return 1

# Detect congestion problems early!
EXPECTED_DURATION = 75
{'fraction_non_alphanumeric': 0.06725213773977351, 'fraction_numerical': 0.008782066096602727, 'mean_word_length': 4.635416666666667, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5163284', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1165, 'n_words': 489}