Cara menggunakan php thread pool example

Pooling provides a higher level abstraction of the Worker functionality, including the management of references in the way required by pthreads. From: http://php.net/manual/en/class.pool.php

Pools and workers provide an higher level of control and ease of creating multi-threaded

workName = $workName;
        printf("A new work was submitted with the name: %s\n", $workName);
    }

    public function run() {
        // This block of code in, the method, run
        // would be called by your worker.
        // All the code in this method will be executed in another thread.
        $workName = $this->workName;
        printf("Work named %s starting...\n", $workName);
        printf("New random number: %d\n", mt_rand());
    }
}

// Create an empty worker for the sake of simplicity.
class AwesomeWorker extends Worker {
    public function run() {
        // You can put some code in here, which would be executed
        // before the Work's are started (the block of code in the `run` method of your Work)
        // by the Worker.
        /* ... */
    }
}

// Create a new Pool Instance.
// The ctor of \Pool accepts two parameters.
// First: The maximum number of workers your pool can create.
// Second: The name of worker class.
$pool = new \Pool(1, \AwesomeWorker::class);

// You need to submit your jobs, rather the instance of
// the objects (works) which extends the \Threaded class.
$pool->submit(new \AwesomeWork("DeadlyWork"));
$pool->submit(new \AwesomeWork("FatalWork"));

// We need to explicitly shutdown the pool, otherwise,
// unexpected things may happen.
// See: http://stackoverflow.com/a/23600861/23602185
$pool->shutdown();

cat APIs are only intended for human consumption using the command line or Kibana console. They are not intended for use by applications. For application consumption, use the nodes info API.

Returns thread pool statistics for each node in a cluster. Returned information includes all built-in thread pools and custom thread pools.

GET /_cat/thread_pool/

GET /_cat/thread_pool

  • If the Elasticsearch security features are enabled, you must have the monitor or manage to use this API.

(Optional, string) Comma-separated list of thread pool names used to limit the request. Accepts wildcard expressions.

format(Optional, string) Short version of the HTTP accept header. Valid values include JSON, YAML, etc.h

(Optional, string) Comma-separated list of column names to display.

If you do not specify which columns to include, the API returns the default columns in the order listed below. If you explicitly specify one or more columns, it only returns the specified columns.

Valid columns are:

GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
0(Default) Node name, such as
GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
1.
GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
2(Default) Name of the thread pool, such as
GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
3 or
GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
4.
GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
5,
GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
6(Default) Number of active threads in the current thread pool.
GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
7,
GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
8(Default) Number of tasks in the queue for the current thread pool.
GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
9,
id                     name    active rejected completed
0EWUhXeBQtaVGlexUeVwMg generic      0        0        70
0(Default) Number of tasks rejected by the thread pool executor.
id                     name    active rejected completed
0EWUhXeBQtaVGlexUeVwMg generic      0        0        70
1,
id                     name    active rejected completed
0EWUhXeBQtaVGlexUeVwMg generic      0        0        70
2Number of tasks completed by the thread pool executor.
id                     name    active rejected completed
0EWUhXeBQtaVGlexUeVwMg generic      0        0        70
3,
id                     name    active rejected completed
0EWUhXeBQtaVGlexUeVwMg generic      0        0        70
4Configured core number of active threads allowed in the current thread pool.
id                     name    active rejected completed
0EWUhXeBQtaVGlexUeVwMg generic      0        0        70
5,
id                     name    active rejected completed
0EWUhXeBQtaVGlexUeVwMg generic      0        0        70
6Ephemeral node ID.
id                     name    active rejected completed
0EWUhXeBQtaVGlexUeVwMg generic      0        0        70
7, hHostname for the current node.
id                     name    active rejected completed
0EWUhXeBQtaVGlexUeVwMg generic      0        0        70
9, GET /_cat/thread_pool/0IP address for the current node.GET /_cat/thread_pool/1, GET /_cat/thread_pool/2Configured keep alive time for threads.GET /_cat/thread_pool/3, GET /_cat/thread_pool/4Highest number of active threads in the current thread pool.GET /_cat/thread_pool/5, GET /_cat/thread_pool/6Configured maximum number of active threads allowed in the current thread pool.GET /_cat/thread_pool/7, GET /_cat/thread_pool/8ID of the node, such as GET /_cat/thread_pool/9.GET /_cat/thread_pool0, GET /_cat/thread_pool1Process ID of the running node.GET /_cat/thread_pool2, GET /_cat/thread_pool3Number of threads in the current thread pool.GET /_cat/thread_pool4, GET /_cat/thread_pool5Bound transport port for the current node.GET /_cat/thread_pool6, GET /_cat/thread_pool7Maximum number of tasks permitted in the queue for the current thread pool.GET /_cat/thread_pool8, GET /_cat/thread_pool9Configured fixed number of active threads allowed in the current thread pool.monitor0, monitor1Type of thread pool. Returned values are monitor2, monitor3, monitor4, or monitor5.

monitor6(Optional, Boolean) If monitor7, the response includes help information. Defaults to monitor8.monitor9(Optional, Boolean) If monitor7, the request retrieves information from the local node only. Defaults to monitor8, which means information is retrieved from the master node.manage2(Optional, ) Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. Defaults to manage3.manage4(Optional, string) Comma-separated list of column names or column aliases used to sort the response.manage5(Optional, ) Unit used to display time values.manage6(Optional, Boolean) If monitor7, the response includes column headings. Defaults to monitor8.

Example with default columnsedit

The API returns the following response:

node-0 analyze             0 0 0
...
node-0 fetch_shard_started 0 0 0
node-0 fetch_shard_store   0 0 0
node-0 flush               0 0 0
...
node-0 write               0 0 0

Example with explicit columnsedit

The following API request returns the GET /_cat/thread_pool/8,

GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
2,
GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
5,
GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
9, and
id                     name    active rejected completed
0EWUhXeBQtaVGlexUeVwMg generic      0        0        70
1 columns. The request limits returned information to the
GET /_cat/thread_pool/generic?v=true&h=id,name,active,rejected,completed
4 thread pool.