Skip to content

Commit

Permalink
Merge pull request #112 from AO-StreetArt/ConnectionPoolUpdates
Browse files Browse the repository at this point in the history
Connection pool updates
  • Loading branch information
AO-StreetArt committed Feb 12, 2018
2 parents 283a001 + 7a187d4 commit ad25c30
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 34 deletions.
12 changes: 12 additions & 0 deletions aossl/mongo/include/factory_mongo.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ class MongoComponentFactory {
return new MongoClient(url, db, collection_name, pool_size);
}

//! Get a Mongo Interface instance
inline MongoInterface* get_mongo_interface(const char * url, const char * db,\
const char * collection_name, int pool_size, int pstart_size, int pbatch) {
return new MongoClient(url, db, collection_name, pool_size, pstart_size, pbatch);
}

//! Get a Mongo Interface instance
inline MongoInterface* get_mongo_interface(std::string url, std::string db, \
std::string collection_name, int pool_size, int pstart_size, int pbatch) {
return new MongoClient(url, db, collection_name, pool_size, pstart_size, pbatch);
}

//! Get a Mongo Interface instance
inline MongoInterface* get_mongo_interface(const char * url, \
const char * db, int pool_size) {
Expand Down
29 changes: 20 additions & 9 deletions aossl/mongo/include/mongo_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class MongoClient: public MongoInterface {

// Initialize the client
void initialize(const char * url, const char * db, \
const char * collection_name, int size);
const char * collection_name, int size, int pstart_size, int pbatch);

public:
// Switch the current collection
Expand All @@ -200,38 +200,49 @@ class MongoClient: public MongoInterface {
// Constructor
inline MongoClient(const char * url, const char * db, \
const char * collection_name) {
initialize(url, db, collection_name, 5);
initialize(url, db, collection_name, 5, 0, 1);
}

inline MongoClient(std::string url, std::string db, \
std::string collection_name) {
initialize(url.c_str(), db.c_str(), collection_name.c_str(), 5);
initialize(url.c_str(), db.c_str(), collection_name.c_str(), 5, 0, 1);
}

inline MongoClient(const char * url, const char * db) {
initialize(url, db, "default", 5);
initialize(url, db, "default", 5, 0, 1);
}

inline MongoClient(std::string url, std::string db) {
initialize(url.c_str(), db.c_str(), "default", 5);
initialize(url.c_str(), db.c_str(), "default", 5, 0, 1);
}

inline MongoClient(const char * url, const char * db, \
const char * collection_name, int pool_size) {
initialize(url, db, collection_name, pool_size);
initialize(url, db, collection_name, pool_size, 0, 1);
}

inline MongoClient(std::string url, std::string db, \
std::string collection_name, int pool_size) {
initialize(url.c_str(), db.c_str(), collection_name.c_str(), pool_size);
initialize(url.c_str(), db.c_str(), collection_name.c_str(), pool_size, 0, 1);
}

inline MongoClient(const char * url, const char * db, \
const char * collection_name, int pool_size, int pstart_size, int pbatch) {
initialize(url, db, collection_name, pool_size, pstart_size, pbatch);
}

inline MongoClient(std::string url, std::string db, \
std::string collection_name, int pool_size, int pstart_size, int pbatch) {
initialize(url.c_str(), db.c_str(), collection_name.c_str(), \
pool_size, pstart_size, pbatch);
}

inline MongoClient(const char * url, const char * db, int pool_size) {
initialize(url, db, "default", pool_size);
initialize(url, db, "default", pool_size, 0, 1);
}

inline MongoClient(std::string url, std::string db, int pool_size) {
initialize(url.c_str(), db.c_str(), "default", pool_size);
initialize(url.c_str(), db.c_str(), "default", pool_size, 0, 1);
}

// Destructor
Expand Down
7 changes: 4 additions & 3 deletions aossl/mongo/mongo_admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ MongoResponseInterface* MongoIterator::next() {
}

void MongoClient::initialize(const char * url, const char * db, \
const char * collection_name, int size) {
const char * collection_name, int size, int pstart_size, int pbatch) {
std::string url_str(url);
std::string db_str(db);
std::string col_str(collection_name);
pool = new MongoConnectionPool(size, url_str, db_str, col_str, 1, 1);
pool = new MongoConnectionPool(size, url_str, db_str, col_str, \
pstart_size, pbatch);
}

MongoClient::~MongoClient() {
Expand Down Expand Up @@ -311,7 +312,7 @@ void MongoConnectionPool::init_connections(std::string conn_str, \
ms.connection = mongoc_client_new(conn_cstr);
connections.push_back(ms);
}
current_max_connection = start_connections;
current_max_connection = start_connections - 1;
}

MongoConnectionPool::~MongoConnectionPool() {
Expand Down
12 changes: 12 additions & 0 deletions aossl/neo4j/include/factory_neo4j.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ class Neo4jComponentFactory {
return new Neo4jAdmin(conn_str, secure, pool_size);
}

//! Get a Neo4j Interface instance
inline Neo4jInterface* get_neo4j_interface(const char * conn_str, \
bool secure, int pool_size, int pstart_size, int pbatch) {
return new Neo4jAdmin(conn_str, secure, pool_size, pstart_size, pbatch);
}

//! Get a Neo4j Interface instance
inline Neo4jInterface* get_neo4j_interface(std::string conn_str, \
bool secure, int pool_size, int pstart_size, int pbatch) {
return new Neo4jAdmin(conn_str, secure, pool_size, pstart_size, pbatch);
}

//! Get a Neo4j Array Query Parameter
inline Neo4jQueryParameterInterface* get_neo4j_query_parameter() {
return new Neo4jQueryParameter();
Expand Down
25 changes: 18 additions & 7 deletions aossl/neo4j/include/neo4j_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,35 @@ THE SOFTWARE.
// Neo4j Admin
class Neo4jAdmin: public Neo4jInterface {
Neo4jConnectionPool *pool = NULL;
void initialize(const char * conn_str, bool secure, int conn_pool_size);
void initialize(const char * conn_str, bool secure, int conn_pool_size, int pool_start_size, int pool_batch_size);

public:
// Initializers
inline Neo4jAdmin(const char * conn_str, bool secure, int pool_size, \
int pstart_size, int pbatch_size) {
initialize(conn_str, secure, pool_size, pstart_size, pbatch_size);
}
inline Neo4jAdmin(std::string conn_str, bool secure, int pool_size, \
int pstart_size, int pbatch_size) {
initialize(conn_str.c_str(), secure, pool_size, pstart_size, pbatch_size);
}
inline Neo4jAdmin(const char * conn_str, bool secure, int pool_size) {
initialize(conn_str, secure, pool_size);
initialize(conn_str, secure, pool_size, 0, 1);
}
inline Neo4jAdmin(std::string conn_str, bool secure, int pool_size) {
initialize(conn_str.c_str(), secure, pool_size);
initialize(conn_str.c_str(), secure, pool_size, 0, 1);
}
inline Neo4jAdmin(const char * conn_str, bool secure) {
initialize(conn_str, secure, 5);
initialize(conn_str, secure, 5, 0, 1);
}
inline Neo4jAdmin(std::string conn_str, bool secure) {
initialize(conn_str.c_str(), secure, 5);
initialize(conn_str.c_str(), secure, 5, 0, 1);
}
Neo4jAdmin(const char * conn_str) {initialize(conn_str, false, 5);}
Neo4jAdmin(std::string conn_str) {initialize(conn_str.c_str(), false, 5);}
Neo4jAdmin(const char * conn_str) {initialize(conn_str, false, 5, 0, 1);}
Neo4jAdmin(std::string conn_str) {initialize(conn_str.c_str(), false, 5, 0, 1);}
// Destructors
~Neo4jAdmin() {if (pool) {delete pool;}}
// Query methods
ResultsIterator* execute(const char * query);
ResultsIterator* execute(std::string query) {return execute(query.c_str());}
ResultsIteratorInterface* execute(const char * query, \
Expand Down
2 changes: 1 addition & 1 deletion aossl/neo4j/include/neo4j_connection_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Neo4jConnectionPool {

connections.push_back(qs);
}
current_max_connection = start_connections;
current_max_connection = start_connections - 1;
}

// Base Startup Routine
Expand Down
6 changes: 4 additions & 2 deletions aossl/neo4j/neo4j_admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ THE SOFTWARE.
#include "include/neo4j_admin.h"

// Start the admin
void Neo4jAdmin::initialize(const char * conn_str, bool secure, int pool_size) {
void Neo4jAdmin::initialize(const char * conn_str, bool secure, int pool_size, \
int pool_start_size, int pool_batch_size) {
// Initialize the Neo4j Database pool
pool = new Neo4jConnectionPool(pool_size, conn_str, secure, 1, 1);
pool = new Neo4jConnectionPool(pool_size, conn_str, secure, \
pool_start_size, pool_batch_size);
}

// Execute a query and return the results in an iterator
Expand Down
14 changes: 14 additions & 0 deletions aossl/redis/include/factory_redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ class RedisComponentFactory {
timeout_seconds, timeout_microseconds, pool_size);
}

//! Get a Redis Interface Instance
inline RedisInterface* get_redis_interface(std::string hostname, int port, \
int timeout_seconds, int timeout_microseconds, int pool_size, \
int pstart_size, int pbatch) {
return new RedisAdmin(hostname, port, \
timeout_seconds, timeout_microseconds, pool_size, pstart_size, pbatch);
}

//! Get a Redis Interface Instance
inline RedisInterface* get_redis_interface(RedisConnChain connection_list) {
return new RedisAdmin(connection_list);
Expand All @@ -78,6 +86,12 @@ class RedisComponentFactory {
int pool_size) {
return new RedisAdmin(connection_list, pool_size);
}

//! Get a Redis Interface Instance
inline RedisInterface* get_redis_interface(RedisConnChain connection_list, \
int pool_size, int pstart_size, int pbatch) {
return new RedisAdmin(connection_list, pool_size, pstart_size, pbatch);
}
};

#endif // AOSSL_REDIS_INCLUDE_FACTORY_REDIS_H_
10 changes: 8 additions & 2 deletions aossl/redis/include/redis_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class RedisAdmin : public RedisInterface {
std::string reply_str;
std::string int_hostname;
RedisConnectionPool *pool = NULL;
void init(std::string hostname, std::string passwd, int port, \
int timeout_seconds, int timeout_microseconds, int pool_size);
void init(std::string hostname, std::string passwd, int port, int timeout_seconds, \
int timeout_microseconds, int pool_size, int pstart_size, int pbatch);
bool process_std_string_reply(redisReply *reply);
bool process_std_int_reply(redisReply *reply);
int return_int_reply(redisReply *reply);
Expand All @@ -127,13 +127,19 @@ class RedisAdmin : public RedisInterface {
int timeout_microseconds);
RedisAdmin(std::string hostname, int port, int timeout_seconds, \
int timeout_microseconds, int pool_size);
RedisAdmin(std::string hostname, int port, int timeout_seconds, \
int timeout_microseconds, int pool_size, int pstart_size, int pbatch);

// Constructors for lists of Redis Connections
RedisAdmin(RedisConnChain connection_list);

// Constructors for lists of Redis Connections
RedisAdmin(RedisConnChain connection_list, int pool_size);

// Constructors for lists of Redis Connections
RedisAdmin(RedisConnChain connection_list, int pool_size, int pstart_size, \
int pbatch);

// Destructor
~RedisAdmin() {if (pool) {delete pool;}}

Expand Down
36 changes: 26 additions & 10 deletions aossl/redis/redis_admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void RedisConnectionPool::init_connections(const char * conn_str, \

connections.push_back(rs);
}
current_max_connection = start_connections;
current_max_connection = start_connections - 1;
}

// Clean up the connection pool
Expand Down Expand Up @@ -152,14 +152,16 @@ void RedisConnectionPool::release_connection(RedisSession *conn) {
// Redis Admin

void RedisAdmin::init(std::string hostname, std::string passwd, int port, \
int timeout_seconds, int timeout_microseconds, int pool_size) {
int timeout_seconds, int timeout_microseconds, int pool_size, \
int pstart_size, int pbatch) {
int_hostname = hostname;
if (passwd.empty()) {
pool = new RedisConnectionPool(pool_size, int_hostname.c_str(), NULL, \
port, timeout_seconds, timeout_microseconds, 1, 1);
port, timeout_seconds, timeout_microseconds, pstart_size, pbatch);
} else {
pool = new RedisConnectionPool(pool_size, int_hostname.c_str(), \
passwd.c_str(), port, timeout_seconds, timeout_microseconds, 1, 1);
passwd.c_str(), port, timeout_seconds, timeout_microseconds, \
pstart_size, pbatch);
}
}

Expand Down Expand Up @@ -227,33 +229,47 @@ AOSSL::StringBuffer* RedisAdmin::return_stringbuf_reply(redisReply *reply) {
}

RedisAdmin::RedisAdmin(std::string hostname, int port) {
init(hostname, "", port, 5, 0, 5);
init(hostname, "", port, 5, 0, 5, 0, 1);
}

RedisAdmin::RedisAdmin(std::string hostname, int port, int pool_size) {
init(hostname, "", port, 5, 0, pool_size);
init(hostname, "", port, 5, 0, pool_size, 0, 1);
}

RedisAdmin::RedisAdmin(std::string hostname, int port, int timeout_seconds, \
int timeout_microseconds) {
init(hostname, "", port, timeout_seconds, timeout_microseconds, 5);
init(hostname, "", port, timeout_seconds, timeout_microseconds, 5, 0, 1);
}

RedisAdmin::RedisAdmin(std::string hostname, int port, int timeout_seconds, \
int timeout_microseconds, int pool_size) {
init(hostname, "", port, timeout_seconds, timeout_microseconds, pool_size);
init(hostname, "", port, timeout_seconds, timeout_microseconds, pool_size, 0, 1);
}

RedisAdmin::RedisAdmin(std::string hostname, int port, int timeout_seconds, \
int timeout_microseconds, int pool_size, int pstart_size, int pbatch) {
init(hostname, "", port, timeout_seconds, timeout_microseconds, pool_size, \
pstart_size, pbatch);
}

RedisAdmin::RedisAdmin(RedisConnChain current_connection) {
// Connect
init(current_connection.ip, current_connection.password, \
current_connection.port, current_connection.timeout, 0, 5);
current_connection.port, current_connection.timeout, 0, 5, 0, 1);
}

RedisAdmin::RedisAdmin(RedisConnChain current_connection, int pool_size) {
// Connect
init(current_connection.ip, current_connection.password, \
current_connection.port, current_connection.timeout, 0, pool_size);
current_connection.port, current_connection.timeout, 0, pool_size, 0, 1);
}

RedisAdmin::RedisAdmin(RedisConnChain current_connection, int pool_size, \
int pstart_size, int pbatch) {
// Connect
init(current_connection.ip, current_connection.password, \
current_connection.port, current_connection.timeout, 0, pool_size, \
pstart_size, pbatch);
}

// Load a value from Redis
Expand Down

0 comments on commit ad25c30

Please sign in to comment.