1
0
mirror of https://github.com/Yubico/yubikey-val.git synced 2025-02-26 21:54:16 +01:00

Increase the parallelism of queue processing.

Since the api servers have 4 vCPUs each we can handle sending them more than
one queue request at a time.
This commit is contained in:
Benno Rice 2019-10-22 13:33:57 +11:00
parent 18ced7b6e7
commit 28f399482b

View File

@ -284,6 +284,8 @@ class SyncLib
$ch = array(); $ch = array();
$entries = array(); $entries = array();
$handles = 0; $handles = 0;
$num_per_server = 4;
$curlopts = $this->curlopts;
while ($my_server = $this->db->fetchArray($server_res)) while ($my_server = $this->db->fetchArray($server_res))
{ {
@ -299,28 +301,37 @@ class SyncLib
$list[] = $entry; $list[] = $entry;
} }
$server_list[$server] = $list; $server_list[$server] = $list;
$handle = curl_init();
$ch[$server] = $handle;
$this->db->closeCursor($res); $this->db->closeCursor($res);
} }
$this->db->closeCursor($server_res); $this->db->closeCursor($server_res);
/* add one entry for each server we're going to sync */ /* add up to n entries for each server we're going to sync */
foreach ($server_list as $server) { foreach ($server_list as $server) {
$entry = array_shift($server); $items = array_slice($server, 0, $num_per_server);
if(count($server) == 0) { $counter = 0;
unset($server_list[$entry['server']]); foreach ($items as $entry) {
} $label = "{$entry['server']}:$counter";
$handle = $ch[$entry['server']]; $handle = curl_init();
$ch[$label] = $handle;
$counter++;
$this->log(LOG_INFO, "server=" . $entry['server'] . ", server_nonce=" . $entry['server_nonce'] . ", info=" . $entry['info']); $this->log(LOG_INFO, "server=" . $entry['server'] . ", server_nonce=" . $entry['server_nonce'] . ", info=" . $entry['info']);
$url = $this->buildSyncUrl($entry); $url = $this->buildSyncUrl($entry);
curl_settings($this, 'YK-VAL resync', $handle, $url, $timeout, $this->curlopts); $curlopts[CURLOPT_PRIVATE] = $label;
$entries[$entry['server']] = $entry;
curl_settings($this, 'YK-VAL resync', $handle, $url, $timeout, $curlopts);
$entries[$label] = $entry;
curl_multi_add_handle($mh, $handle); curl_multi_add_handle($mh, $handle);
$handles++; $handles++;
} }
$empty = array();
array_splice($server, 0, $num_per_server, $empty);
if(count($server) == 0) {
unset($server_list[$entry['server']]);
}
}
while($handles > 0) { while($handles > 0) {
while (curl_multi_exec($mh, $active) == CURLM_CALL_MULTI_PERFORM); while (curl_multi_exec($mh, $active) == CURLM_CALL_MULTI_PERFORM);
@ -328,7 +339,8 @@ class SyncLib
while ($info = curl_multi_info_read($mh)) { while ($info = curl_multi_info_read($mh)) {
$handle = $info['handle']; $handle = $info['handle'];
$server = strtok(curl_getinfo($handle, CURLINFO_EFFECTIVE_URL), "?"); $server = strtok(curl_getinfo($handle, CURLINFO_EFFECTIVE_URL), "?");
$entry = $entries[$server]; $label = curl_getinfo($handle, CURLINFO_PRIVATE);
$entry = $entries[$label];
$this->log(LOG_DEBUG, "handle indicated to be for $server."); $this->log(LOG_DEBUG, "handle indicated to be for $server.");
curl_multi_remove_handle($mh, $handle); curl_multi_remove_handle($mh, $handle);
$handles--; $handles--;
@ -420,7 +432,7 @@ class SyncLib
$this->log(LOG_ERR, 'Remote server refused our sync request. Check remote server logs.'); $this->log(LOG_ERR, 'Remote server refused our sync request. Check remote server logs.');
} }
if($server_list[$server]) { if (array_key_exists($server, $server_list)) {
$entry = array_shift($server_list[$server]); $entry = array_shift($server_list[$server]);
if(count($server_list[$server]) == 0) { if(count($server_list[$server]) == 0) {
$this->log(LOG_DEBUG, "All entries for $server synced."); $this->log(LOG_DEBUG, "All entries for $server synced.");
@ -430,8 +442,9 @@ class SyncLib
$url = $this->buildSyncUrl($entry); $url = $this->buildSyncUrl($entry);
curl_settings($this, 'YK-VAL resync', $handle, $url, $timeout, $this->curlopts); $curlopts[CURLOPT_PRIVATE] = $label;
$entries[$server] = $entry; curl_settings($this, 'YK-VAL resync', $handle, $url, $timeout, $curlopts);
$entries[$label] = $entry;
curl_multi_add_handle($mh, $handle); curl_multi_add_handle($mh, $handle);
$handles++; $handles++;
} }
@ -443,7 +456,7 @@ class SyncLib
} }
foreach ($ch as $handle) { foreach ($ch as $handle) {
curl_close($ch); curl_close($handle);
} }
curl_multi_close($mh); curl_multi_close($mh);