add metrics for ASpell workers

This commit is contained in:
Brian Gough 2015-03-12 09:54:57 +00:00
parent ed33cd59b7
commit 7936269804
2 changed files with 6 additions and 0 deletions

View file

@ -1,5 +1,6 @@
child_process = require("child_process") child_process = require("child_process")
logger = require 'logger-sharelatex' logger = require 'logger-sharelatex'
metrics = require('metrics-sharelatex')
BATCH_SIZE = 100 BATCH_SIZE = 100
@ -9,9 +10,11 @@ class ASpellWorker
@count = 0 @count = 0
@pipe = child_process.spawn("aspell", ["pipe", "-t", "--encoding=utf-8", "-d", language]) @pipe = child_process.spawn("aspell", ["pipe", "-t", "--encoding=utf-8", "-d", language])
logger.log process: @pipe.pid, lang: @language, "starting new aspell worker" logger.log process: @pipe.pid, lang: @language, "starting new aspell worker"
metrics.inc "aspellWorker-start-" + @language
@pipe.on 'exit', () => @pipe.on 'exit', () =>
@state = 'killed' @state = 'killed'
logger.log process: @pipe.pid, lang: @language, "aspell worker has exited" logger.log process: @pipe.pid, lang: @language, "aspell worker has exited"
metrics.inc "aspellWorker-exit-" + @language
@pipe.on 'error', (err) => @pipe.on 'error', (err) =>
@state = 'error' @state = 'error'
@callback err, [] @callback err, []

View file

@ -1,6 +1,7 @@
ASpellWorker = require "./ASpellWorker" ASpellWorker = require "./ASpellWorker"
_ = require "underscore" _ = require "underscore"
logger = require 'logger-sharelatex' logger = require 'logger-sharelatex'
metrics = require('metrics-sharelatex')
class ASpellWorkerPool class ASpellWorkerPool
MAX_REQUESTS: 100*1024 MAX_REQUESTS: 100*1024
@ -18,12 +19,14 @@ class ASpellWorkerPool
worker.pipe.on 'exit', () => worker.pipe.on 'exit', () =>
@cleanup() @cleanup()
@PROCESS_POOL.push(worker) @PROCESS_POOL.push(worker)
metrics.gauge 'aspellWorkerPool-size', @PROCESS_POOL.length
return worker return worker
cleanup: () -> cleanup: () ->
active = @PROCESS_POOL.filter (worker) -> active = @PROCESS_POOL.filter (worker) ->
worker.state != 'killed' worker.state != 'killed'
@PROCESS_POOL = active @PROCESS_POOL = active
metrics.gauge 'aspellWorkerPool-size', @PROCESS_POOL.length
check: (language, words, timeout, callback) -> check: (language, words, timeout, callback) ->
# look for an existing process in the pool # look for an existing process in the pool