Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is connection pooling possible with REST?

Since REST is stateless, each request that comes in has no knowledge of the previous request that comes in. Is connection pooling possible in this situation?

If connection pooling were to be implemented, it would open the connection pool and close it upon each request just like a standard database connection.

How can REST be implemented to take advantage of connection pooling?

like image 996
Atma Avatar asked Jun 12 '12 16:06

Atma


People also ask

When should you not use connection pooling?

You reuse a prior database connection, in a new context to avoid the cost of setting up a new database connection for each request. The primary reason to avoid using database connections is that you're application's approach to solving problems isn't structured to accommodate a database connection pool.

Is connection pooling enabled by default?

By default, connection pooling is enabled in ADO.NET. Unless you explicitly disable it, the pooler optimizes the connections as they are opened and closed in your application. You can also supply several connection string modifiers to control connection pooling behavior.

What are some of the main issues with using connection pools?

One of the most common issues undermining connection pool benefits is the fact that pooled connections can end up being stale. This most often happens due to inactive connections being timed out by network devices between the JVM and the database. As a result, there will be stale connections in the pool.

Is connection pooling necessary?

Using connection pools helps to both alleviate connection management overhead and decrease development tasks for data access. Each time an application attempts to access a backend store (such as a database), it requires resources to create, maintain, and release a connection to that datastore.


2 Answers

You need to understand what is connection pooling (object pool), caching and difference.

Connection pools are created to avoid the expense of creating these expensive resources. They are mostly created and stored somewhere and after being used, they return back to pool and can be used again. this was you avoid the expense of creating these resources over and over. such as database connections.

for REST, how do you make a request to a REST service? lets say over HTTP via PUT,GET, POST etc. so you need HTTP connection. if you are worried about the server, depending on the server you are using, most of them uses threads.

I have a feeling, you might be confused with caching and object pooling. with object pool, just like a thread pool, you create X amount of that object and store it in a pool (usually queue). Whenever you need one, you ask one from the pool. after you are done with it you return it to the pool.

REST in connection pool context make too much sense.

What you might want is caching... REST is stateless but each object has a unique identifier, so you can cache it based on that ID.

like image 177
DarthVader Avatar answered Sep 27 '22 23:09

DarthVader


it certainly would be possible: REST doesn't dictate anything with regards to how your server is built internally but for ignoring state and having a uniform HTTP interface. You could thus have a server process that uses a connection-pool for connecting to your database but that still is perfectly in line with the whole REST, stateless, drop-in component style of design.

like image 42
Harald Brinkhof Avatar answered Sep 27 '22 22:09

Harald Brinkhof