Gearman
Gearman (분산 작업 큐 프레임워크)
많은 작업을 여러 컴퓨터나 프로세스에 나눠 처리하고 싶을 때 쓰는 확장이에요. Gearman은 작업을 여러 머신/프로세스에 분산(farming out)하기 위한 범용 애플리케이션 프레임워크예요. 애플리케이션이 작업을 병렬로 처리하고, 부하를 분산하고, 언어 간에 함수를 호출할 수 있게 해 줘요.
출처: Gearman
본문
소개
Gearman은 작업을 여러 머신이나 프로세스에 분산 처리(farming out)하기 위한 범용 애플리케이션 프레임워크예요. 애플리케이션은 이를 통해 작업을 병렬로 완료하고, 처리를 로드밸런싱하고, 언어 간에 함수를 호출할 수 있어요. 이 프레임워크는 고가용성 웹 사이트부터 데이터베이스 복제 이벤트 전송까지 다양한 애플리케이션에 쓰일 수 있어요.
이 확장은 Gearman 클라이언트와 워커(worker)를 작성하기 위한 클래스를 제공해요. 클라이언트가 작업을 제출하고, 워커가 그 작업을 수행하고 결과를 돌려주는 구조로 이해하면 돼요.
클래스 참조
GearmanClient — The GearmanClient class
클라이언트 쪽에서 작업을 제출하고 결과를 받는 데 쓰는 클래스예요.
GearmanClient::addOptions— Add client optionsGearmanClient::addServer— Add a job server to the clientGearmanClient::addServers— Add a list of job servers to the clientGearmanClient::addTask— Add a task to be run in parallelGearmanClient::addTaskBackground— Add a background task to be run in parallelGearmanClient::addTaskHigh— Add a high priority task to run in parallelGearmanClient::addTaskHighBackground— Add a high priority background task to be run in parallelGearmanClient::addTaskLow— Add a low priority task to run in parallelGearmanClient::addTaskLowBackground— Add a low priority background task to be run in parallelGearmanClient::addTaskStatus— Add a task to get statusGearmanClient::clearCallbacks— Clear all task callback functionsGearmanClient::clone— Create a copy of a GearmanClient objectGearmanClient::__construct— Create a GearmanClient instanceGearmanClient::context— Get the application contextGearmanClient::data— Get the application data (deprecated)GearmanClient::do— Run a single task and return a result [deprecated]GearmanClient::doBackground— Run a task in the backgroundGearmanClient::doHigh— Run a single high priority taskGearmanClient::doHighBackground— Run a high priority task in the backgroundGearmanClient::doJobHandle— Get the job handle for the running taskGearmanClient::doLow— Run a single low priority taskGearmanClient::doLowBackground— Run a low priority task in the backgroundGearmanClient::doNormal— Run a single task and return a resultGearmanClient::doStatus— Get the status for the running taskGearmanClient::echo— Send data to all job servers to see if they echo it back [deprecated]GearmanClient::error— Returns an error string for the last error encounteredGearmanClient::getErrno— Get an errno valueGearmanClient::jobStatus— Get the status of a background jobGearmanClient::ping— Send data to all job servers to see if they echo it backGearmanClient::removeOptions— Remove client optionsGearmanClient::returnCode— Get the last Gearman return codeGearmanClient::runTasks— Run a list of tasks in parallelGearmanClient::setClientCallback— Callback function when there is a data packet for a task (deprecated)GearmanClient::setCompleteCallback— Set a function to be called on task completionGearmanClient::setContext— Set application contextGearmanClient::setCreatedCallback— Set a callback for when a task is queuedGearmanClient::setData— Set application data (deprecated)GearmanClient::setDataCallback— Callback function when there is a data packet for a taskGearmanClient::setExceptionCallback— Set a callback for worker exceptionsGearmanClient::setFailCallback— Set callback for job failureGearmanClient::setOptions— Set client optionsGearmanClient::setStatusCallback— Set a callback for collecting task statusGearmanClient::setTimeout— Set socket I/O activity timeoutGearmanClient::setWarningCallback— Set a callback for worker warningsGearmanClient::setWorkloadCallback— Set a callback for accepting incremental data updatesGearmanClient::timeout— Get current socket I/O activity timeout valueGearmanClient::wait— Wait for I/O activity on all connections in a client
GearmanJob — The GearmanJob class
워커 쪽에서 실행 중인 작업(잡)을 나타내는 클래스예요.
GearmanJob::complete— Send the result and complete status (deprecated)GearmanJob::__construct— Create a GearmanJob instanceGearmanJob::data— Send data for a running job (deprecated)GearmanJob::exception— Send exception for running job (deprecated)GearmanJob::fail— Send fail status (deprecated)GearmanJob::functionName— Get function nameGearmanJob::handle— Get the job handleGearmanJob::returnCode— Get last return codeGearmanJob::sendComplete— Send the result and complete statusGearmanJob::sendData— Send data for a running jobGearmanJob::sendException— Send exception for running job (exception)GearmanJob::sendFail— Send fail statusGearmanJob::sendStatus— Send statusGearmanJob::sendWarning— Send a warningGearmanJob::setReturn— Set a return valueGearmanJob::status— Send status (deprecated)GearmanJob::unique— Get the unique identifierGearmanJob::warning— Send a warning (deprecated)GearmanJob::workload— Get workloadGearmanJob::workloadSize— Get size of work load
GearmanTask — The GearmanTask class
제출된 개별 작업(태스크)을 나타내는 클래스예요.
GearmanTask::__construct— Create a GearmanTask instanceGearmanTask::create— Create a task (deprecated)GearmanTask::data— Get data returned for a taskGearmanTask::dataSize— Get the size of returned dataGearmanTask::function— Get associated function name (deprecated)GearmanTask::functionName— Get associated function nameGearmanTask::isKnown— Determine if task is knownGearmanTask::isRunning— Test whether the task is currently runningGearmanTask::jobHandle— Get the job handleGearmanTask::recvData— Read work or result data into a buffer for a taskGearmanTask::returnCode— Get the last return codeGearmanTask::sendData— Send data for a task (deprecated)GearmanTask::sendWorkload— Send data for a taskGearmanTask::taskDenominator— Get completion percentage denominatorGearmanTask::taskNumerator— Get completion percentage numeratorGearmanTask::unique— Get the unique identifier for a taskGearmanTask::uuid— Get the unique identifier for a task (deprecated)
GearmanWorker — The GearmanWorker class
작업을 실제로 수행하는 워커를 나타내는 클래스예요.
GearmanWorker::addFunction— Register and add callback functionGearmanWorker::addOptions— Add worker optionsGearmanWorker::addServer— Add a job serverGearmanWorker::addServers— Add job serversGearmanWorker::clone— Create a copy of the workerGearmanWorker::__construct— Create a GearmanWorker instanceGearmanWorker::echo— Test job server responseGearmanWorker::error— Get the last error encounteredGearmanWorker::getErrno— Get errnoGearmanWorker::options— Get worker optionsGearmanWorker::register— Register a function with the job serverGearmanWorker::removeOptions— Remove worker optionsGearmanWorker::returnCode— Get last Gearman return codeGearmanWorker::setId— Give the worker an identifier so it can be tracked when asking gearmand for the list of available workersGearmanWorker::setOptions— Set worker optionsGearmanWorker::setTimeout— Set socket I/O activity timeoutGearmanWorker::timeout— Get socket I/O activity timeoutGearmanWorker::unregister— Unregister a function name with the job serversGearmanWorker::unregisterAll— Unregister all function names with the job serversGearmanWorker::wait— Wait for activity from one of the job serversGearmanWorker::work— Wait for and perform jobs
예외 클래스
GearmanException— The GearmanException class
더 알아보기
- 클라이언트가
addTask()로 작업을 모아runTasks()로 병렬 실행하는 방식이 핵심이에요. 배경(background) 작업은 응답을 기다리지 않으니 오래 걸리는 작업에 적합해요. - deprecated로 표시된 메서드들은 새 API(
sendComplete,setDataCallback등)로 대체된 것들이에요. 새 코드에서는 대체 API를 쓰는 게 좋아요.