-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connection pools #189
Open
AlexanderSuprunenko
wants to merge
15
commits into
development/v.0.0.2
Choose a base branch
from
feature/connection-bunches
base: development/v.0.0.2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Connection pools #189
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1fd8867
Debug info extracted into separate files.
AlexanderSuprunenko 1eec471
Extracting debug info enhanced.
AlexanderSuprunenko 3ab797e
GraftServerTest.genericCallback test fixed.
AlexanderSuprunenko 623aad7
Extracting debug info messages enhanced.
AlexanderSuprunenko 81f5082
Merge pull request #179 from graft-project/feature/extract-debug
AlexanderSuprunenko 9c5c57c
UpstreamManager dependency on TaskManager removed.
AlexanderSuprunenko 8ddb26b
static uri_substitutions removed from OutHttp. makeUri test fixed.
AlexanderSuprunenko 6695481
upstreamKeepAlive test improved. Simulated test cryptonode supports m…
AlexanderSuprunenko d3bfd64
Connection Bunches added.
AlexanderSuprunenko f502890
In config.ini rpc-address can be one of [upstream]
AlexanderSuprunenko 7c9ad69
New tests added based on UpstreamTest fixture.
AlexanderSuprunenko 6147dc2
In config.ini in [upstream] item format changed.
AlexanderSuprunenko 9400eb8
makeUri test fixed.
AlexanderSuprunenko fc2bd9d
[upstream] section entry format description updated.
AlexanderSuprunenko adcc8d9
Config.ini [upstream] item format changed.
AlexanderSuprunenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#pragma once | ||
#include "lib/graft/connection.h" | ||
|
||
|
||
namespace graft | ||
{ | ||
|
||
class UpstreamManager | ||
{ | ||
public: | ||
using OnDoneCallback = std::function<void(UpstreamSender& uss)>; | ||
UpstreamManager() = default; | ||
|
||
void init(const ConfigOpts& copts, mg_mgr* mgr, int http_callback_port, OnDoneCallback onDoneCallback); | ||
|
||
bool busy() const | ||
{ | ||
return (m_cntUpstreamSender != m_cntUpstreamSenderDone); | ||
} | ||
|
||
void send(BaseTaskPtr& bt); | ||
protected: | ||
//testGetUri for test only | ||
const std::string testGetUri(const Output& output); | ||
private: | ||
class ConnItem | ||
{ | ||
public: | ||
using ConnectionId = uint64_t; | ||
using IpPort = std::string; | ||
using Uri = std::string; | ||
|
||
struct Bunch | ||
{ | ||
int m_connCnt = 0; | ||
std::map<mg_connection*, ConnectionId> m_idleConnections; | ||
std::map<ConnectionId, mg_connection*> m_activeConnections; | ||
UpstreamStub m_upstreamStub; | ||
}; | ||
|
||
ConnItem() = default; | ||
ConnItem(int uriId, const std::string& uri, int maxConnections, bool keepAlive, double timeout) | ||
: m_uriId(uriId) | ||
, m_uri(uri) | ||
, m_maxConnections(maxConnections) | ||
, m_keepAlive(keepAlive) | ||
, m_timeout(timeout) | ||
{ | ||
} | ||
~ConnItem() | ||
{ | ||
for(auto& it : m_bunches) | ||
{ | ||
auto& b = it.second; | ||
assert(b.m_idleConnections.empty()); | ||
assert(b.m_activeConnections.empty()); | ||
} | ||
} | ||
|
||
std::pair<ConnectionId, mg_connection*> getConnection(const IpPort& ip_port); | ||
void releaseActive(ConnectionId connectionId, const IpPort& ip_port, mg_connection* client); | ||
void onCloseIdle(const IpPort& ip_port, mg_connection* client); | ||
Bunch& getBunch(const IpPort& ip_port, bool createIfNotExists = false); | ||
|
||
int m_uriId; | ||
std::string m_uri; | ||
double m_timeout; | ||
int m_maxConnections; | ||
std::deque< std::tuple<BaseTaskPtr,IpPort,Uri> > m_taskQueue; | ||
bool m_keepAlive = false; | ||
std::map<IpPort, Bunch> m_bunches; | ||
private: | ||
ConnectionId m_newId = 0; | ||
}; | ||
|
||
void onDone(UpstreamSender& uss, ConnItem* connItem, const std::string& ip_port, ConnItem::ConnectionId connectionId, mg_connection* client); | ||
void createUpstreamSender(ConnItem* connItem, const std::string& ip_port, BaseTaskPtr bt, const std::string& uri); | ||
ConnItem* findConnItem(const Output& output, std::string& ip_port, std::string& result_uri); | ||
const std::string& getUri(ConnItem* connItem, const std::string& inputUri); | ||
|
||
using Uri2ConnItem = std::map<std::string, ConnItem>; | ||
|
||
OnDoneCallback m_onDoneCallback; | ||
uint64_t m_cntUpstreamSender = 0; | ||
uint64_t m_cntUpstreamSenderDone = 0; | ||
ConnItem m_default; | ||
Uri2ConnItem m_conn2item; | ||
mg_mgr* m_mgr = nullptr; | ||
int m_http_callback_port; | ||
protected: | ||
std::unordered_map<std::string,std::string> m_resolveCache; | ||
}; | ||
|
||
}//namespace graft | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format is very confusing and not self-explanatory, especially "keepAlive" - why just don't have it as last optional parameter? e.g.:
address[, timeout[, max_connections, [keep_alive]]]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, suggesting following format:
because connections limit and keep alive are unrelated entities and right now
keepAlive
flag implicitly switches limit's scope (upstream limit vs address (aka unique host:port record))There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comma-separated values with variable number of arguments are horrible and non-descriptive. How about: