Skip to content
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

Add documentation about psycopg pool and application configuration #18

Open
drnextgis opened this issue Nov 17, 2021 · 4 comments
Open
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed

Comments

@drnextgis
Copy link
Contributor

When I run titiler-pgstac using docker-compose and try to add tile service to QGIS I see these errors in console:

titiler-pgstac | [2021-11-17 19:08:48 +0000] [8] [ERROR] Exception in ASGI application
titiler-pgstac | Traceback (most recent call last):
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 396, in run_asgi
titiler-pgstac |     result = await app(self.scope, self.receive, self.send)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
titiler-pgstac |     return await self.app(scope, receive, send)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/fastapi/applications.py", line 199, in __call__
titiler-pgstac |     await super().__call__(scope, receive, send)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/starlette/applications.py", line 112, in __call__
titiler-pgstac |     await self.middleware_stack(scope, receive, send)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
titiler-pgstac |     raise exc from None
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
titiler-pgstac |     await self.app(scope, receive, _send)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 25, in __call__
titiler-pgstac |     response = await self.dispatch_func(request, self.call_next)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/titiler/core/middleware.py", line 38, in dispatch
titiler-pgstac |     response = await call_next(request)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 45, in call_next
titiler-pgstac |     task.result()
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 38, in coro
titiler-pgstac |     await self.app(scope, receive, send)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/starlette/middleware/cors.py", line 78, in __call__
titiler-pgstac |     await self.app(scope, receive, send)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
titiler-pgstac |     raise exc from None
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
titiler-pgstac |     await self.app(scope, receive, sender)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 580, in __call__
titiler-pgstac |     await route.handle(scope, receive, send)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 241, in handle
titiler-pgstac |     await self.app(scope, receive, send)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 52, in app
titiler-pgstac |     response = await func(request)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 219, in app
titiler-pgstac |     raw_response = await run_endpoint_function(
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 154, in run_endpoint_function
titiler-pgstac |     return await run_in_threadpool(dependant.call, **values)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/starlette/concurrency.py", line 40, in run_in_threadpool
titiler-pgstac |     return await loop.run_in_executor(None, func, *args)
titiler-pgstac |   File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
titiler-pgstac |     result = self.fn(*self.args, **self.kwargs)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/titiler/pgstac/factory.py", line 157, in tile
titiler-pgstac |     data, _ = src_dst.tile(
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/titiler/pgstac/mosaic.py", line 216, in tile
titiler-pgstac |     mosaic_assets = self.assets_for_tile(
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/titiler/pgstac/mosaic.py", line 139, in assets_for_tile
titiler-pgstac |     return self.get_assets(Polygon.from_bounds(*bbox), **kwargs)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/cachetools/__init__.py", line 520, in wrapper
titiler-pgstac |     v = func(*args, **kwargs)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/titiler/pgstac/mosaic.py", line 175, in get_assets
titiler-pgstac |     conn = self.pool.getconn()
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/psycopg2/pool.py", line 169, in getconn
titiler-pgstac |     return self._getconn(key)
titiler-pgstac |   File "/usr/local/lib/python3.8/site-packages/psycopg2/pool.py", line 92, in _getconn
titiler-pgstac |     raise PoolError("connection pool exhausted")
titiler-pgstac | psycopg2.pool.PoolError: connection pool exhausted
@drnextgis
Copy link
Contributor Author

Should we consider switching to psycopg3 pool as suggested here?

@vincentsarago
Copy link
Member

maybe we should start by trying https://github.com/microsoft/planetary-computer-apis/blob/main/pctiler/pctiler/db.py#L62-L92

I'm not quite sure of the implication of using psycopg 3 yet.

@vincentsarago
Copy link
Member

vincentsarago commented Nov 30, 2021

@drnextgis in #21, I've switched to psycopg3 but the pool exhausted message can still append. This just tells that there is a misconfiguration (too many connection to one pool) so this needs to be solved by changing the POOL configuration or the number of workers used.

I've used https://github.com/bdon/TileSiege to perform a benchmark. I'll push the code in #21. But the TLDR, is that you have to carefully choose how many worker (and concurrent request) an application can handle.

cc @lossyrob

@vincentsarago vincentsarago changed the title psycopg2.pool.PoolError: connection pool exhausted Add documentation about psycopg pool and application configuration Nov 30, 2021
@vincentsarago vincentsarago added documentation Improvements or additions to documentation help wanted Extra attention is needed labels Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants