예제 #1
0
파일: basic.py 프로젝트: timkordas/soa-sim
import simpy

from SimComponents import RequestGenerator, RequestSink, RandomBrancher

if __name__ == '__main__':
    # random-variables for distribution of requests
    # inter-request-time distribution
    idist = functools.partial(random.expovariate, 2.0)
    # request cost distribution
    mean_cost = 100
    cdist = functools.partial(random.expovariate, 1.0 / mean_cost)

    # Create the SimPy environment. This is the thing that runs the simulation.
    env = simpy.Environment()

    gen = RequestGenerator(env,
                           "external",
                           idist,
                           cdist,
                           initial_delay=50,
                           finish=1000)

    # Create the packet generators and sink
    def selector(req):
        return req.src == "external"

    sink = RequestSink(env, debug=True, rec_arrivals=True, selector=selector)

    gen.out = sink
    env.run(until=2000)
    sink = RequestSink(env, debug=True, rec_arrivals=True, selector=None)

    n_completers = 15
    completers = [None] * n_completers
    for i in range(n_completers):
        completers[i] = RequestCompleter(env)
        completers[i].out = sink

    completers[0].extra_delay_factor = 2.5

    generators = []
    branchers = []
    count = 10
    for i in range(count):
        generators.append(
            RequestGenerator(env,
                             "genA" + str(i),
                             idist,
                             cdist,
                             initial_delay=50,
                             finish=3000))
        branchers.append(PQueueBrancher(env, completers))
        generators[i].out = branchers[i]

    env.run(until=45000)

    for i in range(n_completers):
        print("{} reqs: {} hiwater {} inflight {}".format(
            i, completers[i].requests_rec, completers[i].hiwat,
            branchers[0].inflight[i]))
예제 #3
0
# Two generators, going into two priority-queue branchers, with 15 shared completers
if __name__ == '__main__':
    # random-variables for distribution of requests
    # inter-request-time distribution
    idist = functools.partial(random.expovariate, 2.0)
    # request cost distribution
    mean_cost = 10
    cdist = functools.partial(random.expovariate, 1.0 / mean_cost)

    # Create the SimPy environment. This is the thing that runs the simulation.
    env = simpy.Environment()

    gen1 = RequestGenerator(env,
                            "one",
                            idist,
                            cdist,
                            initial_delay=50,
                            finish=3000)
    gen2 = RequestGenerator(env,
                            "two",
                            idist,
                            cdist,
                            initial_delay=50,
                            finish=3000)

    # Create the packet generators and sink
    def selector(req):
        return req.src == "one"

    sink = RequestSink(env, debug=True, rec_arrivals=True, selector=selector)
예제 #4
0
import simpy

from SimComponents import RequestGenerator, RequestSink, RequestCompleter, SynchronousForwarder, RandomBrancher

if __name__ == '__main__':
    # random-variables for distribution of requests
    # inter-request-time distribution
    idist = functools.partial(random.expovariate, 2.0)
    # request cost distribution
    mean_cost = 100
    cdist = functools.partial(random.expovariate, 1.0/mean_cost)

    # Create the SimPy environment. This is the thing that runs the simulation.
    env = simpy.Environment()

    gen = RequestGenerator(env, "external", idist, cdist, initial_delay=50)

    # Create the packet generators and sink
    def selector(req):
        return req.src == "external"

    sink = RequestSink(env, debug=True, rec_arrivals=True, selector=selector)

    completer = RequestCompleter(env)
    completer.out = sink

    forwarder = SynchronousForwarder(env, N=1)
    forwarder.out = completer

    gen.out = forwarder
    env.run(until=4000)