def test_state_json_performance(self):
        framework_id = 'frameworkid'
        changes_request_limit = 53

        blpath = self.test_dir + '/blacklist'
        blacklist = open(blpath, 'w+')
        blacklist.write('hostname1\nhostname2\n')
        blacklist.close()

        api = mock.Mock(spec=ChangesAPI)
        cs = ChangesScheduler(state_file=None,
                              api=api,
                              blacklist=FileBlacklist(blpath),
                              changes_request_limit=changes_request_limit)
        cs.framework_id = framework_id
        driver = mock.Mock()
        now = time.time()

        offer1 = self._make_offer(id='offer1', hostname='host1', cpus=1, mem=1024)
        offer2 = self._make_offer(id='offer2', hostname='host1', cpus=2, mem=2048)
        offer3 = self._make_offer(id='offer3', hostname='host3', cpus=4, mem=4096,
                                  cluster='some_cluster')
        offer4 = self._make_offer(hostname='host4',
                                  id='offer4',
                                  cpus=5,
                                  mem=5000,
                                  unavailability_start_secs=now - 5,
                                  unavailability_duration_secs=100)
        offer4.attributes.add(name="ranges_example",
                              type=mesos_pb2.Value.RANGES,
                              ranges=mesos_pb2.Value.Ranges(range=[
                                  mesos_pb2.Value.Range(begin=10, end=20),
                                  mesos_pb2.Value.Range(begin=30, end=40),
                              ]))
        offer4.attributes.add(name="set_example",
                              type=mesos_pb2.Value.SET,
                              set=mesos_pb2.Value.Set(item=[
                                  'string_1',
                                  'string_2',
                              ]))
                              
        cs.resourceOffers(driver, [offer1, offer2, offer3, offer4])

        tasks = [
            self._make_changes_task('1', mem=3072, snapshot='snap1'),
            self._make_changes_task('2', mem=4096, snapshot='snap2'),
        ]
        api.get_allocate_jobsteps.return_value = tasks
        api.post_allocate_jobsteps.return_value = ['1', '2']
        assert not cs.poll_and_launch_once(driver)

        start_time = time.time()
        loops = 1000
        for i in xrange(loops):
            state_json = cs.state_json()
        total_time = time.time() - start_time

        max_avg_time_per_loop = .05
        assert total_time < max_avg_time_per_loop * loops
Verify that the /state_json handler can build its JSON payload in
dataset/ETHPy150Open dropbox/changes-mesos-framework/changes_mesos_scheduler/tests/test_changes_scheduler.py/ChangesSchedulerTest.test_state_json_performance