def _get_board_bitmap(self): # Since we're not using MinimalController, we need to setup the # baseplate span manually to have access to the baseplate context. baseplate_integration.make_server_span( span_name="place.GET_board_bitmap").start() response = RedisCanvas.get_board() baseplate_integration.finish_server_span() return response
def restore_redis_board_from_cass(): """ Get all pixels from cassandra and put them back into redis. """ baseplate_integration.make_server_span('shell').start() # Get from cass st = time.time() canvas = Canvas.get_all() print "time to get canvas from cass: ", time.time() - st # Calculate bitmap st = time.time() bitmap = ['\x00'] * ((CANVAS_HEIGHT * CANVAS_WIDTH + 1) / 2) for (x, y), json_data in canvas.iteritems(): # These shouldn't be in cassandra but are for some reason. The # frontend only displays up to 999, 999 anyway. if x > 999 or y > 999: continue color = json_data['color'] # We're putting 2 integers into a single byte. If the integer is # an odd number, we can just OR it onto the byte, since we want it # at the end. If it's an even number, it needs to go at the # beginning of the byte, so we shift it first. offset = y * CANVAS_WIDTH + x if offset % 2 == 0: color = color << 4 # Update the color in the bitmap. Because division rounds down, we # can simply divide by 2 to find the correct byte in the bitmap. bitmap_idx = offset / 2 updated_bitmap_int = ord(bitmap[bitmap_idx]) | color packed_color = struct.pack('B', updated_bitmap_int) bitmap[bitmap_idx] = packed_color print "time to get generate canvas for redis: ", time.time() - st # Set to redis st = time.time() c.place_redis.set(CANVAS_ID, ''.join(bitmap)) print "time to set canvas to redis: ", time.time() - st
def GET_pixel(self, event, **kwargs): extension = request.environ.get("extension") if extension != "png": abort(404) with baseplate_integration.make_server_span( "liveupdatepixelcontroller.GET_pixel"): record_activity(event) response.content_type = "image/png" response.headers["Cache-Control"] = "no-cache, max-age=0" response.headers["Pragma"] = "no-cache" response.headers["Expires"] = "Thu, 01 Jan 1970 00:00:00 GMT" return self._pixel_contents
def wrap_processor(msgs, *args): # Work the same for amqp.consume_items and amqp.handle_items. msg_tup = utils.tup(msgs) metrics_name = "amqp." + queue_name start = time.time() try: with baseplate_integration.make_server_span(metrics_name): return processor(msgs, *args) finally: service_time = (time.time() - start) / len(msg_tup) for n, msg in enumerate(msg_tup): fake_start = start + n * service_time fake_end = fake_start + service_time self.transact(metrics_name, fake_start, fake_end) self.flush()