File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
src/setup/deployment/raw-code/serverless/gcr/hellopy-read-random Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ FROM python:3.7-alpine
2+
3+ RUN pip install Flask gunicorn
4+
5+ WORKDIR /app
6+ COPY . .
7+
8+ CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app
Original file line number Diff line number Diff line change 1+ import json
2+ import os
3+ import time
4+ import random
5+ from flask import Flask , request
6+
7+ app = Flask (__name__ )
8+
9+
10+ @app .route ('/' )
11+ def hello_world ():
12+ incr_limit = 0
13+ if request .args and 'incrementLimit' in request .args :
14+ incr_limit = request .args .get ('incrementLimit' )
15+
16+ read_filler_file ("./filler.file" )
17+ simulate_work (incr_limit )
18+
19+ response = {
20+ "statusCode" : 200 ,
21+ "headers" : {
22+ "Content-Type" : "application/json"
23+ },
24+ "body" : {
25+ "RequestID" : "gcr-does-not-specify" ,
26+ "TimestampChain" : [str (time .time_ns ())],
27+ }
28+ }
29+
30+ return json .dumps (response , indent = 4 )
31+
32+
33+ def simulate_work (incr ):
34+ num = 0
35+ while num < incr :
36+ num += 1
37+
38+
39+ def read_filler_file (path : str ) -> None :
40+ file_size = os .stat (path ).st_size
41+ number_of_pages = file_size // 4096
42+ with open (path , 'rb' ) as f :
43+ for _ in range (100 ):
44+ page_number = random .randrange (0 , number_of_pages )
45+ page_offset = page_number * 4096
46+ f .seek (page_offset )
47+ f .read (1 )
48+
49+
50+ if __name__ == "__main__" :
51+ app .run (debug = True , host = '0.0.0.0' , port = int (os .environ .get ('PORT' , 8080 )))
You can’t perform that action at this time.
0 commit comments