Esempio n. 1
0
# limitations under the License.

from client import Client
from scenario_five import scenario_five
from scheduler import scheduler
from simulation import run_scenario


# Choose two random clients and spike their wanted capacity to 1000.
def spike():
  client1 = Client.get_random_client()
  client2 = client1

  while client1 == client2:
    client2 = Client.get_random_client()

  client1.set_wants('resource0', 1000)
  client2.set_wants('resource0', 1000)


# Like scenario five, but at t=150 two random clients spike their
# wanted capacity to 1000.
def scenario_six(reporter):
  scenario_five(reporter)
  reporter.set_filename('scenario_six')

  scheduler.add_absolute(150, lambda: spike())

if __name__ == '__main__':
  run_scenario(lambda reporter: scenario_six(reporter))
Esempio n. 2
0
# See the License for the specific language governing permissions and
# limitations under the License.

from client import Client
from server_job import ServerJob
from simulation import run_scenario


# Scenario 4: The simplest possible tree of servers, consisting of a
# regional job and a root job. Then five clients, pretty much like
# scenario one.
# resource0 has capacity of 500.  Root server job with three tasks, five
# clients with randomly varying resource need around 100. No special
# effects.
def scenario_four(reporter):
  root_job = ServerJob('root', 0, 3)
  regional_job = ServerJob('regional', 1, 3, root_job)

  for i in xrange(0, 5):
    c = Client('client', regional_job)
    c.add_resource('resource0', 0, 100, 0.1, 10)

  reporter.schedule('resource0')
  reporter.set_filename('scenario_four')

  return regional_job


if __name__ == '__main__':
  run_scenario(lambda reporter: scenario_four(reporter))
Esempio n. 3
0
# Copyright 2016 Google, Inc.
#
# 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.

from scenario_one import scenario_one
from scheduler import scheduler
from simulation import run_scenario


# Scenario 2: Same as scenario 1, but with server failure and
# master election at T=120.
def scenario_two(reporter):
  job = scenario_one(reporter)
  scheduler.add_relative(120, lambda: job.lose_master())
  scheduler.add_relative(140, lambda: job.trigger_master_election())
  reporter.set_filename('scenario_two')


if __name__ == '__main__':
  run_scenario(lambda reporter: scenario_two(reporter))
Esempio n. 4
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.

from client import Client
from server_job import ServerJob
from simulation import run_scenario


# Scenario 1: A simple scenario to show convergence.
# resource0 has capacity of 500.  Root server job with three tasks, five
# clients with randomly varying resource needs.
def scenario_one(reporter):
  job = ServerJob('root', 0, 3)

  for i in xrange(0, 5):
    c = Client('client', job)
    c.add_resource('resource0', 0, 110, 0.1, 10)

  reporter.schedule('resource0')
  reporter.set_filename('scenario_one')

  return job


if __name__ == '__main__':
  run_scenario(lambda reporter: scenario_one(reporter))
Esempio n. 5
0
# Copyright 2016 Google, Inc.
#
# 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.

from scenario_one import scenario_one
from scheduler import scheduler
from simulation import run_scenario


# Scenario 2: Same as scenario 1, but with server failure and
# master election at T=120.
def scenario_two(reporter):
    job = scenario_one(reporter)
    scheduler.add_relative(120, lambda: job.lose_master())
    scheduler.add_relative(140, lambda: job.trigger_master_election())
    reporter.set_filename('scenario_two')


if __name__ == '__main__':
    run_scenario(lambda reporter: scenario_two(reporter))
Esempio n. 6
0
from client import Client
from scenario_five import scenario_five
from scheduler import scheduler
from simulation import run_scenario


# Choose two random clients and spike their wanted capacity to 1000.
def spike():
    client1 = Client.get_random_client()
    client2 = client1

    while client1 == client2:
        client2 = Client.get_random_client()

    client1.set_wants('resource0', 1000)
    client2.set_wants('resource0', 1000)


# Like scenario five, but at t=150 two random clients spike their
# wanted capacity to 1000.
def scenario_six(reporter):
    scenario_five(reporter)
    reporter.set_filename('scenario_six')

    scheduler.add_absolute(150, lambda: spike())


if __name__ == '__main__':
    run_scenario(lambda reporter: scenario_six(reporter))
Esempio n. 7
0
def random_mishap():
    scheduler.add_relative(60, lambda: random_mishap())

    total = max(_mishap_map.keys())
    m = random.randint(0, total - 1)
    n = 0

    for (key, value) in _mishap_map.iteritems():
        if n >= m:
            Counter.get('mishap.%d' % key).inc()
            value()
            return

        n += key

    assert False


# Uses the setup of scenario five, but runs for a (simulated) hour
# and invokes random mishap every 60 seconds.


def scenario_seven(reporter):
    scenario_five(reporter)
    reporter.set_filename('scenario_seven')
    scheduler.add_absolute(60, lambda: random_mishap())


if __name__ == '__main__':
    run_scenario(lambda reporter: scenario_seven(reporter), run_for=3600)
Esempio n. 8
0
# 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.

from client import Client
from server_job import ServerJob
from simulation import run_scenario


# All out massive scenario: 9 datacenters, three regions, one root
# server.
def scenario_five(reporter, num_clients=5):
  root_job = ServerJob('root', 0, 3)

  for i in xrange(1, 4):
    region_job = ServerJob('region:%i' % i, 1, 3, root_job)

    for j in xrange(1, 4):
      dc_job = ServerJob('dc:%d:%d' % (i, j), 2, 3, region_job)

      for k in xrange(1, num_clients + 1):
        client = Client('client:%d:%d' % (i, j), dc_job)
        client.add_resource('resource0', 0, 15, 0.1, 10)

  reporter.schedule('resource0')
  reporter.set_filename('scenario_five')


if __name__ == '__main__':
  run_scenario(lambda reporter: scenario_five(reporter))
Esempio n. 9
0
# 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.

from client import Client
from server_job import ServerJob
from simulation import run_scenario


# All out massive scenario: 9 datacenters, three regions, one root
# server.
def scenario_five(reporter, num_clients=5):
    root_job = ServerJob('root', 0, 3)

    for i in xrange(1, 4):
        region_job = ServerJob('region:%i' % i, 1, 3, root_job)

        for j in xrange(1, 4):
            dc_job = ServerJob('dc:%d:%d' % (i, j), 2, 3, region_job)

            for k in xrange(1, num_clients + 1):
                client = Client('client:%d:%d' % (i, j), dc_job)
                client.add_resource('resource0', 0, 15, 0.1, 10)

    reporter.schedule('resource0')
    reporter.set_filename('scenario_five')


if __name__ == '__main__':
    run_scenario(lambda reporter: scenario_five(reporter))
Esempio n. 10
0

def random_mishap():
  scheduler.add_relative(60, lambda: random_mishap())

  total = max(_mishap_map.keys())
  m = random.randint(0, total - 1)
  n = 0

  for (key, value) in _mishap_map.iteritems():
    if n >= m:
      Counter.get('mishap.%d' % key).inc()
      value()
      return

    n += key

  assert False

# Uses the setup of scenario five, but runs for a (simulated) hour
# and invokes random mishap every 60 seconds.


def scenario_seven(reporter):
  scenario_five(reporter)
  reporter.set_filename('scenario_seven')
  scheduler.add_absolute(60, lambda: random_mishap())

if __name__ == '__main__':
  run_scenario(lambda reporter: scenario_seven(reporter), run_for=3600)
Esempio n. 11
0
# See the License for the specific language governing permissions and
# limitations under the License.

from client import Client
from server_job import ServerJob
from simulation import run_scenario


# Scenario 4: The simplest possible tree of servers, consisting of a
# regional job and a root job. Then five clients, pretty much like
# scenario one.
# resource0 has capacity of 500.  Root server job with three tasks, five
# clients with randomly varying resource need around 100. No special
# effects.
def scenario_four(reporter):
    root_job = ServerJob('root', 0, 3)
    regional_job = ServerJob('regional', 1, 3, root_job)

    for i in xrange(0, 5):
        c = Client('client', regional_job)
        c.add_resource('resource0', 0, 100, 0.1, 10)

    reporter.schedule('resource0')
    reporter.set_filename('scenario_four')

    return regional_job


if __name__ == '__main__':
    run_scenario(lambda reporter: scenario_four(reporter))
Esempio n. 12
0
# Copyright 2016 Google, Inc.
#
# 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.

from scenario_one import scenario_one
from scheduler import scheduler
from simulation import run_scenario


# Scenario 3: Same as scenario 2, but now we let the leases
# expire before the server comes back.
def scenario_three(reporter):
  job = scenario_one(reporter)
  scheduler.add_relative(120, lambda: job.lose_master())
  scheduler.add_relative(190, lambda: job.trigger_master_election())
  reporter.set_filename('scenario_three')


if __name__ == '__main__':
  run_scenario(lambda reporter: scenario_three(reporter))