mirror of
https://github.com/sogou/workflow.git
synced 2026-10-21 22:56:42 +08:00
@@ -187,7 +187,7 @@ const EndpointAddress *EndpointGroup::get_one()
|
||||
const EndpointAddress *addr = NULL;
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
|
||||
std::random_shuffle(this->mains.begin(), this->mains.end());
|
||||
std::shuffle(this->mains.begin(), this->mains.end(), this->gen);
|
||||
for (size_t i = 0; i < this->mains.size(); i++)
|
||||
{
|
||||
if (this->mains[i]->fail_count < this->mains[i]->params->max_fails)
|
||||
@@ -199,7 +199,7 @@ const EndpointAddress *EndpointGroup::get_one()
|
||||
|
||||
if (!addr)
|
||||
{
|
||||
std::random_shuffle(this->backups.begin(), this->backups.end());
|
||||
std::shuffle(this->backups.begin(), this->backups.end(), this->gen);
|
||||
for (size_t i = 0; i < this->backups.size(); i++)
|
||||
{
|
||||
if (this->backups[i]->fail_count < this->backups[i]->params->max_fails)
|
||||
@@ -222,7 +222,7 @@ const EndpointAddress *EndpointGroup::get_one_backup()
|
||||
const EndpointAddress *addr = NULL;
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
|
||||
std::random_shuffle(this->backups.begin(), this->backups.end());
|
||||
std::shuffle(this->backups.begin(), this->backups.end(), this->gen);
|
||||
for (size_t i = 0; i < this->backups.size(); i++)
|
||||
{
|
||||
if (this->backups[i]->fail_count < this->backups[i]->params->max_fails)
|
||||
|
||||
@@ -20,8 +20,10 @@
|
||||
#define _UPSTREAM_POLICIES_H_
|
||||
|
||||
#include <pthread.h>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <random>
|
||||
#include "URIParser.h"
|
||||
#include "EndpointParams.h"
|
||||
#include "WFNameService.h"
|
||||
@@ -56,13 +58,16 @@ public:
|
||||
UPSGroupPolicy *policy;
|
||||
struct rb_node rb;
|
||||
pthread_mutex_t mutex;
|
||||
std::random_device rd;
|
||||
std::mt19937 gen;
|
||||
std::vector<EndpointAddress *> mains;
|
||||
std::vector<EndpointAddress *> backups;
|
||||
std::atomic<int> nalives;
|
||||
int weight;
|
||||
|
||||
EndpointGroup(int group_id, UPSGroupPolicy *policy) :
|
||||
mutex(PTHREAD_MUTEX_INITIALIZER)
|
||||
mutex(PTHREAD_MUTEX_INITIALIZER),
|
||||
gen(rd())
|
||||
{
|
||||
this->id = group_id;
|
||||
this->policy = policy;
|
||||
|
||||
Reference in New Issue
Block a user