コード例 #1
0
ファイル: memcache.py プロジェクト: AppScale/appscale
def set(uuid):
  """ Stores items in the Memcache and times them.

  Args:
    uuid: A unique identifier as part of the keynames of items.
  Returns:
    A tuple of two lists. A list of float times to store all items,
    and a list of errors. A zero value signifies a failure.
  """
  timings = []
  errors = []

  for index in range(0, constants.NUM_SAMPLES):
    random_string = util.random_string(constants.MAX_STRING_LENGTH)

    start = time.time()
    try:
      # Incorporate uuid in the value to be set.
      memcache.set(uuid + str(index), str(uuid) + random_string)
      total_time = time.time() - start
    except Exception, exception:
      logging.exception(exception)
      errors.append(str(exception))
      total_time = 0

    timings.append(total_time * constants.SECONDS_TO_MILLI)
コード例 #2
0
ファイル: db.py プロジェクト: AppScale/appscale
def put(uuid):
  """ Stores entities in the datastore and time them. 

  Args:
    uuid: A str, unique identifier attached to all entities.
  Returns:
    A tuple of two list. A list of float times to store 
    all entities, and a list of errors. A zero value signifies 
    a failure.
  """
  timings = []
  errors = []
  for index in range(0, constants.NUM_SAMPLES):
    random_blob = util.random_string(constants.MAX_STRING_LENGTH)
    test_model = TestModel(key_name=uuid + str(index),
      test_string=uuid, text_blob=random_blob)
    start = time.time()
    try:
      test_model.put()
      total_time = time.time() - start
    except Exception, exception:
      logging.exception(exception)
      errors.append(str(exception))
      total_time = 0
    timings.append(total_time * constants.SECONDS_TO_MILLI)
コード例 #3
0
ファイル: db.py プロジェクト: sgwd/appscale
def put(uuid):
    """ Stores entities in the datastore and time them. 

  Args:
    uuid: A str, unique identifier attached to all entities.
  Returns:
    A tuple of two list. A list of float times to store 
    all entities, and a list of errors. A zero value signifies 
    a failure.
  """
    timings = []
    errors = []
    for index in range(0, constants.NUM_SAMPLES):
        random_blob = util.random_string(constants.MAX_STRING_LENGTH)
        test_model = TestModel(key_name=uuid + str(index),
                               test_string=uuid,
                               text_blob=random_blob)
        start = time.time()
        try:
            test_model.put()
            total_time = time.time() - start
        except Exception, exception:
            logging.exception(exception)
            errors.append(str(exception))
            total_time = 0
        timings.append(total_time * constants.SECONDS_TO_MILLI)
コード例 #4
0
ファイル: test_smt.py プロジェクト: ramjk/angela
 def test_med_batch_insert(self):
     values = [random_string() for _ in range(100)]
     leaves = [
         random_index(digest_size=SparseMerkleTree.TREE_DEPTH)
         for _ in range(100)
     ]
     self.T.batch_insert({k: v for (k, v) in zip(leaves, values)})
     for idx in leaves:
         proof = self.T.generate_proof(idx)
         self.assertEqual(len(proof.copath), SparseMerkleTree.TREE_DEPTH)
         self.assertTrue(self.T.verify_proof(proof))
コード例 #5
0
ファイル: test_client.py プロジェクト: ramjk/angela
    def test_practice(self):
        indices = [util.random_index() for i in range(128)]
        data = [util.random_string() for i in range(128)]

        print("Inserting")
        for i in range(128):
            Client.insert_leaf(indices[i], data[i])

        print("Getting root")
        root = Client.get_signed_root()

        print("Proving")
        for i in range(128):
            proof = Client.generate_proof(indices[i])
            d = data[i]
            self.assertTrue(Client.verify_proof(proof, d, root))
コード例 #6
0
def benchmark():
    global request_count
    num_inserts = int(request.args.get('num_inserts'))

    print("Generating workload...")
    indices = [random_index() for i in range(num_inserts)]
    data = [random_string() for i in range(num_inserts)]

    for i in range(num_inserts):
        worker_id = calculate_worker_id(indices[i], ray_info['prefix_length'])
        print("Sending insert request to worker {}".format(worker_id))
        ray.get(ray_info['leaf_workers'][worker_id].queue_write.remote(
            indices[i], data[i]))

    request_count += num_inserts
    print("Workload generated")
    return "Workload generated", 200
コード例 #7
0
  def test_get_test(self):
    mock = flexmock(memc)

    # Test execution without exceptions.
    value = 'xxx' + util.random_string(constants.MAX_STRING_LENGTH)
    mock.should_receive("get").and_return(value)
    results = memcache.get('xxx')
    self.assertEquals(len(results), 2)
    self.assertEquals(len(results[0]), constants.NUM_SAMPLES)
    self.assertEquals(len(results[1]), 0)

    # Test with exceptions being thrown up.
    mock.should_receive("get").and_raise(Exception("test exception"))
    results = memcache.get('xxx')
    self.assertEquals(len(results), 2)
    self.assertEquals(len(results[0]), constants.NUM_SAMPLES)

    # All puts caused an exception.
    self.assertEquals(len(results[1]), constants.NUM_SAMPLES)
コード例 #8
0
    def test_get_test(self):
        mock = flexmock(memc)

        # Test execution without exceptions.
        value = 'xxx' + util.random_string(constants.MAX_STRING_LENGTH)
        mock.should_receive("get").and_return(value)
        results = memcache.get('xxx')
        self.assertEquals(len(results), 2)
        self.assertEquals(len(results[0]), constants.NUM_SAMPLES)
        self.assertEquals(len(results[1]), 0)

        # Test with exceptions being thrown up.
        mock.should_receive("get").and_raise(Exception("test exception"))
        results = memcache.get('xxx')
        self.assertEquals(len(results), 2)
        self.assertEquals(len(results[0]), constants.NUM_SAMPLES)

        # All puts caused an exception.
        self.assertEquals(len(results[1]), constants.NUM_SAMPLES)
コード例 #9
0
    ],
                           stdout=subprocess.DEVNULL,
                           stderr=subprocess.DEVNULL)
    time.sleep(5)
    iterations = int(max_batch / batch_size)
    for i in range(iterations):
        print("    [Iteration {}]".format(i))

        inserts = 0
        indices = list()
        datas = list()

        while inserts < batch_size:
            is_member = util.flip_coin(bias=0.75)
            index = util.random_index()
            data = util.random_string()
            if is_member:
                Client.insert_leaf(index, data)
                inserts += 1
            indices.append(index)
            datas.append(data)
            soundness_total += 1
        root = Client.get_signed_root()
        print("Root received")
        for i in range(batch_size):
            proof = Client.generate_proof(indices[i])
            data = datas[i]
            if not Client.verify_proof(proof, data, root):
                # print("Proof Type IN TEST SOUNDNESS", proof.ProofType)
                print("FAILED")
                soundness_error += 1
コード例 #10
0
ファイル: profile_smt.py プロジェクト: ramjk/angela
import cProfile, pstats, merkle.smt
from common import util

keys = [util.random_index() for i in range(100)]
values = [util.random_string() for i in range(100)]
proofs = list()
T = merkle.smt.SparseMerkleTree("sha256")

T_batch = merkle.smt.SparseMerkleTree("sha256")


def profile_inserts():
    pr = cProfile.Profile()

    for i in range(100):
        pr.enable()
        T.insert(keys[i], values[i])
        pr.disable()

    with open("profiles/profile_inserts.txt", 'w') as output:
        p = pstats.Stats(pr, stream=output)
        p.sort_stats('time')
        p.print_stats()


def profile_prover():
    pr = cProfile.Profile()

    for i in range(100):
        pr.enable()
        proofs.append(T.generate_proof(keys[i]))