示例#1
0
def request_generator(env: FaasSimEnvironment, arrival_profile: RandomSampler, request_factory):
    sampler = BufferedSampler(arrival_profile)

    try:
        while True:
            ia = sampler.sample()
            logger.debug('next request: %.4f', ia)
            env.request_queue.put(request_factory())
            yield env.timeout(ia)
    except simpy.Interrupt:
        logger.info('request generator interrupted')
        pass
示例#2
0
    def __init__(self,
                 max_image_variety=None,
                 pareto=True,
                 image_synthesizer=None) -> None:
        super().__init__()
        self.max_image_variety = max_image_variety

        if pareto:
            # 80% of pods will be assigned the same 20% of images
            self.image_id_sampler = BufferedSampler(
                IntegerTruncationSampler(
                    ScaledParetoSampler(0, max_image_variety)))
        else:
            self.image_id_sampler = None

        self.image_synthesizer = image_synthesizer or ImageSynthesizer()
示例#3
0
 def __init__(self, execution_times: Dict[Tuple[str, str],
                                          Tuple[float, float, PDist]]):
     self.execution_times = execution_times
     self.execution_time_samplers = {
         k: BoundRejectionSampler(BufferedSampler(dist), xmin, xmax)
         for k, (xmin, xmax, dist) in execution_times.items()
     }
示例#4
0
 def __init__(self) -> None:
     super().__init__()
     self.execution_time_samplers = {
         k: BoundRejectionSampler(BufferedSampler(dist), xmin, xmax)
         for k, (xmin, xmax, dist) in execution_time_distributions.items()
     }
示例#5
0
文件: perf.py 项目: phip123/faas-sim
 def __init__(self) -> None:
     self.sampler = BufferedSampler(IntegerSampler(10, 1000))
示例#6
0
文件: perf.py 项目: phip123/faas-sim
    class RandomFloatDict:
        def __init__(self) -> None:
            self.sampler = BufferedSampler(IntegerSampler(10, 1000))

        def __getitem__(self, item):
            return self.sampler.sample()
示例#7
0
class MLWorkflowPodSynthesizer:
    def __init__(self,
                 max_image_variety=None,
                 pareto=True,
                 image_synthesizer=None) -> None:
        super().__init__()
        self.max_image_variety = max_image_variety

        if pareto:
            # 80% of pods will be assigned the same 20% of images
            self.image_id_sampler = BufferedSampler(
                IntegerTruncationSampler(
                    ScaledParetoSampler(0, max_image_variety)))
        else:
            self.image_id_sampler = None

        self.image_synthesizer = image_synthesizer or ImageSynthesizer()

    def get_image_states(self) -> Dict[str, ImageState]:
        return self.image_synthesizer.get_image_states()

    def create_workflow_pods(self, instance_id) -> Tuple[Pod, Pod, Pod]:
        image_id = self.get_image_id(instance_id)

        return (self.create_ml_wf_1_pod(instance_id,
                                        image_id,
                                        pod_id=instance_id * 3 + 0),
                self.create_ml_wf_2_pod(instance_id,
                                        image_id,
                                        pod_id=instance_id * 3 + 1),
                self.create_ml_wf_3_pod(instance_id,
                                        image_id,
                                        pod_id=instance_id * 3 + 2))

    def get_image_id(self, instance_id):
        if self.image_id_sampler:
            image_id = self.image_id_sampler.sample()
        else:
            image_id = instance_id % self.max_image_variety if self.max_image_variety else instance_id
        return image_id

    def create_ml_wf_1_pod(self, instance_id: int, image_id: int,
                           pod_id: int) -> Pod:
        image, _ = self.image_synthesizer.create_ml_wf_1_image(image_id)

        raw_data = f'bucket_{instance_id}/raw_data'
        train_data = f'bucket_{instance_id}/train_data'

        return create_pod(pod_id,
                          image_name=image,
                          memory='100Mi',
                          labels={
                              'data.skippy.io/receives-from-storage': '12Mi',
                              'data.skippy.io/sends-to-storage': '209Mi',
                              'data.skippy.io/receives-from-storage/path':
                              raw_data,
                              'data.skippy.io/sends-to-storage/path':
                              train_data
                          })

    def create_ml_wf_2_pod(self, instance_id: int, image_id: int,
                           pod_id: int) -> Pod:
        image, _ = self.image_synthesizer.create_ml_wf_2_image(image_id)

        train_data = f'bucket_{instance_id}/train_data'
        serialized_model = f'bucket_{instance_id}/model'

        return create_pod(pod_id,
                          image_name=image,
                          memory='1Gi',
                          labels={
                              'capability.skippy.io/nvidia-cuda':
                              '10',
                              'capability.skippy.io/nvidia-gpu':
                              '',
                              'data.skippy.io/receives-from-storage':
                              '209Mi',
                              'data.skippy.io/sends-to-storage':
                              '1500Ki',
                              'data.skippy.io/receives-from-storage/path':
                              train_data,
                              'data.skippy.io/sends-to-storage/path':
                              serialized_model
                          })

    def create_ml_wf_3_pod(self, instance_id: int, image_id: int,
                           pod_id: int) -> Pod:
        image, _ = self.image_synthesizer.create_ml_wf_3_image(image_id)
        serialized_model = f'bucket_{instance_id}/model'

        return create_pod(pod_id,
                          image_name=image,
                          labels={
                              'data.skippy.io/receives-from-storage':
                              '1500Ki',
                              'data.skippy.io/receives-from-storage/path':
                              serialized_model
                          })
示例#8
0
def exp_sampler(lambd):
    sampler = BufferedSampler(PDist.expon(lambd))
    while True:
        yield sampler.sample()