Ask: can we close a connection in pool automatically?
I don't see how closing immediately would be faster in the long run. I suppose if a burst of requests was received very quickly you might save time because you are opening fewer new connections, as they get recycled faster.

In my opinion its foolish to override the transaction APIs. Should you wish to run the same application code with a non-pooled database, the behavior is going to be non-obvious, which is the cardinal sin.

Just call `db.close()` when its safe to release the connection, or use the database instance as a context manager.
One of the best practices about connection management is close it when you are done. Normally a hook after request will take this job. like this:

```Python
@hook('after_request')
def _close_db():
    if not db.is_closed():
        db.close()
```

But I am wondering can we close the connection as soon as possible? especially in connection pool, since you can "return" the connection and get it back from the pool very fast. This will be very useful when you finish your database job, but still have to wait a long job before you can finish the request, like this:

```Python
@get('/')
def index():
    foo = Foo.get_by_id(1)
    bar = requests.get('/fetch-bar')
    return foo.name + bar.text
```
You can see before we get `bar` info by HTTP, we already don't need the connection, we can "return" this connection back to pool. 

Sure we can close the connection manually, but there will be lots of db operations in a project. I think it will be great if this job can be done automatically. So I try to overwrite `commit`, `rollback` and `atomic` this three methods of `Database`, like this:

```Python
class AutoReturnPooledMySQL(PooledMySQLDatabase):
    def commit(self):
        super(AutoReturnPooledMySQL, self).commit()
        if not self.in_transaction():
            self.close()

    def rollback(self):
        super(AutoReturnPooledMySQL, self).rollback()
        if not self.in_transaction():
            self.close()

    def atomic(self):
        ctx = super(AutoReturnPooledMySQL, self).atomic()
        return _auto_return_atomic(ctx)


class _auto_return_atomic:
    def __init__(self, ctx):
        self.ctx = ctx

    def __enter__(self):
        return self.ctx.__enter__()

    def __exit__(self, exc_type, exc_val, exc_tb):
        e = self.ctx.__exit__(exc_type, exc_val, exc_tb)

        if not self.ctx.db.in_transaction():
            self.ctx.db.close()

        return e

db = AutoReturnPooledMySQL(None)
```

In my test, the auto-close connection pool indeed increase the system's performance when lots of concurrent requests comes. But still, I don't know if this kind of modification is good or bad, or is there any hidden risk. I just write my thoughts down, and hope there will be an answer after a discussion, thank you.