Example #1
0
#encoding: utf-8

import sys, os
import time
import pso


def log_msg(msg):
    print('{}. {}'.format(os.getpid(), msg))


if len(sys.argv) >= 1 and sys.argv[1] != 'run':
    print('2. my pid {}'.format(os.getpid()))
    status = pso.connect(sys.argv[1])
    print('2. Connected to coordinator {}'.format(status))
    pso.set_random_flinch(True)
    import test1
    pso.transient_start()  # not needed anymore
    test1.run_child()
else:
    import subprocess
    print('1. my pid {}'.format(os.getpid()))
    coord_name = pso.init()
    pso.set_random_flinch(True)
    pso.set_debug_reclaimer(True)
    pso.transient_start()
    pso.pso(2)
    p = pso.ShmPromise()
    root = pso.root()
    root.signal = p
    root.signal2 = pso.ShmPromise()
Example #2
0
    if new_sum != original_sum:
        raise Exception('Sums do not match')

    accounts = pso.root().accounts
    print(f'Root contention (r, w): {pso.get_contention_count(accounts)}')
    contentions = [
        pso.get_contention_count(accounts[f'client{i}'])
        for i in range(number_of_accounts)
    ]
    print(f'Items contentions (r, w): {contentions}')
    del accounts
    pso.root().accounts = None
    #input("Press Enter to continue...")
else:
    # worker process
    pso.connect(sys.argv[2])
    accounts = pso.root().accounts
    attempts = 0
    commits = 0
    for i in range(100 * 1000 // pso.root().worker_count):
        source_index = random.randrange(number_of_accounts)
        target_index = random.randrange(number_of_accounts)
        source = f'client{source_index}'
        target = f'client{target_index}'

        amount = random.randrange(1, 50)
        if source != target:

            @pso.transaction
            def transaction():
                global attempts
Example #3
0
import sys
import pso
import subprocess

if len(sys.argv) != 3:
    # main process
    coord_name = pso.init()
    pso.root().requests = [{
        'idx': i,
        'request': f'request {i}'
    } for i in range(10)]
    pso.root().responses = [None] * 10
    workers = [
        subprocess.Popen(
            [sys.executable, sys.argv[0], coord_name,
             str(req['idx'])]) for req in pso.root().requests
    ]
    statuses = [w.wait(5) for w in workers]
    for (idx, response) in pso.root().responses:
        print((idx, response))
else:
    # worker process
    pso.connect(sys.argv[1])
    myindex = int(sys.argv[2])
    myrequest = pso.root().requests[myindex]
    import time, random
    time.sleep(random.randrange(2))  # imitate some long work
    pso.root().responses[myindex] = \
        (myindex, f'response {myindex} for {myrequest["request"]}')