Mercurial > piecrust2
comparison piecrust/baking/worker.py @ 421:4a43d7015b75
bake: Improve performance timers reports.
Add timers per-worker, and separate bake and pipeline workers.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 20 Jun 2015 23:27:39 -0700 |
parents | 0e9a94b7fdfa |
children | a8a12f97addf |
comparison
equal
deleted
inserted
replaced
420:f1b759c188b0 | 421:4a43d7015b75 |
---|---|
50 work_start_time = time.perf_counter() | 50 work_start_time = time.perf_counter() |
51 | 51 |
52 # Create the app local to this worker. | 52 # Create the app local to this worker. |
53 app = PieCrust(self.ctx.root_dir, debug=self.ctx.debug) | 53 app = PieCrust(self.ctx.root_dir, debug=self.ctx.debug) |
54 app.env.fs_cache_only_for_main_page = True | 54 app.env.fs_cache_only_for_main_page = True |
55 app.env.registerTimer("Worker_%d" % self.wid) | 55 app.env.registerTimer("BakeWorker_%d_Total" % self.wid) |
56 app.env.registerTimer("BakeWorkerInit") | |
56 app.env.registerTimer("JobReceive") | 57 app.env.registerTimer("JobReceive") |
57 | 58 |
58 # Create the job handlers. | 59 # Create the job handlers. |
59 job_handlers = { | 60 job_handlers = { |
60 JOB_LOAD: LoadJobHandler(app, self.ctx), | 61 JOB_LOAD: LoadJobHandler(app, self.ctx), |
61 JOB_RENDER_FIRST: RenderFirstSubJobHandler(app, self.ctx), | 62 JOB_RENDER_FIRST: RenderFirstSubJobHandler(app, self.ctx), |
62 JOB_BAKE: BakeJobHandler(app, self.ctx)} | 63 JOB_BAKE: BakeJobHandler(app, self.ctx)} |
63 for jt, jh in job_handlers.items(): | 64 for jt, jh in job_handlers.items(): |
64 app.env.registerTimer(type(jh).__name__) | 65 app.env.registerTimer(type(jh).__name__) |
66 | |
67 app.env.stepTimerSince("BakeWorkerInit", work_start_time) | |
65 | 68 |
66 # Start working! | 69 # Start working! |
67 aborted_with_exception = None | 70 aborted_with_exception = None |
68 while not self.ctx.abort_event.is_set(): | 71 while not self.ctx.abort_event.is_set(): |
69 try: | 72 try: |
89 if aborted_with_exception is not None: | 92 if aborted_with_exception is not None: |
90 msgs = _get_errors(aborted_with_exception) | 93 msgs = _get_errors(aborted_with_exception) |
91 self.ctx.results.put_nowait({'type': 'error', 'messages': msgs}) | 94 self.ctx.results.put_nowait({'type': 'error', 'messages': msgs}) |
92 | 95 |
93 # Send our timers to the main process before exiting. | 96 # Send our timers to the main process before exiting. |
94 app.env.stepTimer("Worker_%d" % self.wid, | 97 app.env.stepTimerSince("BakeWorker_%d_Total" % self.wid, |
95 time.perf_counter() - work_start_time) | 98 work_start_time) |
96 self.ctx.results.put_nowait({ | 99 self.ctx.results.put_nowait({ |
97 'type': 'timers', 'data': app.env._timers}) | 100 'type': 'timers', 'data': app.env._timers}) |
98 | 101 |
99 | 102 |
100 class JobHandler(object): | 103 class JobHandler(object): |
185 | 188 |
186 self.ctx.results.put_nowait(result) | 189 self.ctx.results.put_nowait(result) |
187 | 190 |
188 | 191 |
189 class RenderFirstSubJobHandler(JobHandler): | 192 class RenderFirstSubJobHandler(JobHandler): |
193 def __init__(self, app, ctx): | |
194 super(RenderFirstSubJobHandler, self).__init__(app, ctx) | |
195 | |
190 def handleJob(self, job): | 196 def handleJob(self, job): |
191 # Render the segments for the first sub-page of this page. | 197 # Render the segments for the first sub-page of this page. |
192 fac = job.payload.factory_info.build(self.app) | 198 fac = job.payload.factory_info.build(self.app) |
193 | 199 |
194 # These things should be OK as they're checked upstream by the baker. | 200 # These things should be OK as they're checked upstream by the baker. |