Adaptive connection pooling for multi-tenant applications
Communication connections with databases, such as when deployed as a database layer of a system architecture, are resource intensive to establish, take down, and maintain. However, from the applications' perspective, deployed in a business logic layer, more database connections result in less delay interacting with the databases. In order to optimize system resources, systems and methods are disclosed that create an optimized number of database connections and/or application connections, that are then maintained and shared by the applications via a proxy intercepting the communications and forwarding the communications to the database via the optimized number of pooled database connections. The connections may be multiplex so that simultaneous communications may be hosted concurrently.
1 . A method, comprising:
intercepting, at a database interface of a proxy, communications from a plurality of applications that are directed to a database layer comprising a plurality of databases;
analyzing the communications directed to the database layer to determine an optimized number of database connections to connect the database layer to the plurality of applications;
establishing the optimized number of database connections;
receiving, at an application interface of the proxy comprising the optimized number of database connections, communications directed to one or more of the plurality of applications received via the optimized number of database connections; and
forwarding the communications directed to the one or more of the plurality of applications via the optimized number of database connections,
wherein analyzing the communications directed to the database layer to determine the optimized number of database connections to connect the database layer to the plurality of applications, comprises determining, based on the communications directed to the database layer that determines a current resource score for a current number of database connections to connect the database layer to the plurality of applications and a candidate resource score comprising one or more of a delay imposed by the current number of database connections being shared by the plurality of applications, a delay reduction imposed by incrementing the current number of database connections being shared by the plurality of applications, a delay increase imposed by decrementing the current number of database connections being shared by the plurality of applications, a setup resource cost to increment the current number of database connections being shared by the plurality of applications, a teardown resource cost imposed by decrementing the current number of database connections being shared by the plurality of applications, and an active resource cost imposed by maintaining the current number of database connections being shared by the plurality of applications.
2 . The method of claim 1 , wherein analyzing the communications directed to the database layer to determine the optimized number of database connections comprises:
determining a number of database requests within the communications from the plurality of applications that are directed to the database layer; and
setting the optimized number of database connections in accordance with the number of database requests.
3 . The method of claim 1 , further comprising, in response to receiving the communications directed to one or more of the plurality of applications received via the optimized number of database connections, unwrapping the communications directed to one or more of the plurality of applications using a message identifier for each of the communications directed to one or more of the plurality of applications; and
forwarding the communications directed to the one or more of the plurality of applications via the optimized number of database connections comprises multiplexing, by the proxy, the communications directed to the one or more of the plurality of applications.
4 . The method of claim 1 , wherein:
one of the optimized number of database connections comprises communications directed to both a first application of the one or more of the plurality of applications and a second application of the one or more of the plurality of applications; and
wherein forwarding, by the proxy, a first communication of the communications directed to the first application of the one or more of the plurality of applications and a second communication of the communications directed to the second application of the one or more of the plurality of applications.
5 . The method of claim 1 , wherein analyzing the communications directed to the database layer to determine the optimized number of database connections to connect the database layer to the plurality of applications comprises:
generating a prompt comprising the communications directed to the database layer;
analyzing the communications directed to the database layer to determine the optimized number of database connections, and return the optimized number of database connections; and
providing the prompt to an artificial intelligence (AI) and receive the optimized number of database connections therefrom.
6 . The method of claim 1 , wherein analyzing the communications directed to the database layer to determine the optimized number of database connections to connect the database layer to the plurality of applications, comprises providing the communications to an artificial intelligence (AI) trained to receive communications and determine therefrom the optimized number of database connections.
7 . The method of claim 1 , wherein intercepting, at the database interface of the proxy, communications from the plurality of applications that are directed to the database layer further comprises repurposing a setSchema call from one of the plurality of applications in accordance with one of the plurality of databases associated with the one of the plurality of applications.
8 . The method of claim 1 , wherein intercepting, at the database interface of the proxy, communications from the plurality of applications that are directed to the database layer further comprises executing a control pane to intercept communications from the plurality of applications that are directed to the database layer.
9 . A system, comprising:
a network connection to a network;
a processor coupled to a computer memory having instructions that, when read by the processor, cause the processor to:
intercept communications from a plurality of applications that are directed to a database layer comprising a plurality of databases;
analyze the intercepted communications directed to the database layer to determine an optimized number of database connections to connect the database layer to the plurality of applications;
establish the optimized number of database connections;
receive communications directed to ones of the plurality of applications received via the optimized number of database connections; and
forward the received communications directed to the one or more of the plurality of applications to the plurality of applications via the optimized number of database connections,
wherein analyzing the communications directed to the database layer to determine the optimized number of database connections to connect the database layer to the plurality of applications, comprises determining, based on the intercepted communications directed to the database layer that determines a current resource score for a current number of database connections to connect the database layer to the plurality of applications and a candidate resource score comprising one or more of a delay imposed by the current number of database connections being shared by the plurality of applications, a delay reduction imposed by incrementing the current number of database connections being shared by the plurality of applications, a delay increase imposed by decrementing the current number of database connections being shared by the plurality of applications, a setup resource cost to increment the current number of database connections being shared by the plurality of applications, a teardown resource cost imposed by decrementing the current number of database connections being shared by the plurality of applications, and an active resource cost imposed by maintaining the current number of database connections being shared by the plurality of applications.
10 . The system of claim 9 , wherein the instructions to cause the processor to analyze the communications directed to the database layer to determine the optimized number of database connections to connect the database layer to the plurality of applications, further comprise instructions to cause the processor to:
generate a prompt comprising the communications directed to the database layer;
analyze the communications directed to the database layer to determine the optimized number of database connections, and return the optimized number of database connections; and
provide the prompt to an artificial intelligence (AI) and receive the optimized number of database connections therefrom.
11 . The system of claim 9 , wherein:
one of the optimized number of database connections comprises communications directed to both a first application of the one or more of the plurality of applications and a second application of the one or more of the plurality of applications; and
further comprising instructions to cause the processor to forward a first communication of the communications directed to the first application of the one or more of the plurality of applications and a second communication of the communications directed to the second application of the one or more of the plurality of applications.