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

Handle with AioPool #221

Closed
kalombos opened this issue May 3, 2024 · 2 comments
Closed

Handle with AioPool #221

kalombos opened this issue May 3, 2024 · 2 comments
Milestone

Comments

@kalombos
Copy link
Collaborator

kalombos commented May 3, 2024

На данный момент AioPool выполняет роль адаптера для возможности использовать различные пулы(aiopg, aiomysql, в перспективе psycopg3) а также в нём есть функционал автоматического создания пула при первом получении connect-а, метода acquire. Вопросы:

  1. Нельзя ли воспользоваться функционалом автоконнекта непосредственно из пулов(aiopg, aiomysql), есть ли у них такая возможность? Насколько я знаю, aiopg пул по дефолту при создании сразу создает один коннект к базе, нет ли у него такой настройки, что коннект создавался только при вызове acquire?
  2. В acquire дважды происходит проверка if self.pool is None это сделано для того, чтобы не использовать блокировку в aсquire без необходимости. Нельзя ли сделать этот код более "красивым"? Не подойдет ли condition для этого случая?
  3. Для закрытия пула используется метод terminate? Чем он отличается от close, может быть стоит использовать close?
  4. Не будет ли гонки при закрытии пула? Мы закрываем пул, в acquire нет блокировки, не будет ли тут ошибки, что у None нет метода acquire?
  5. Стоит ли присваивать pool = None при закрытии пула, то есть давать возможность переоткрытия пула? Как будто бы в этом нет необходимости, если пришлось закрыть пул, то в нём уже нет необходимости

At the moment, AioPool acts as an adapter for the ability to use various pools (aiopg, aiomysql, in the future psycopg3) and it also has the functionality of automatically creating a pool the first time it receives connect, the acquire method. Questions:

  1. Is it possible to use the auto-connect functionality directly from pools (aiopg, aiomysql), do they have such an option? As far as I know, the aiopg pool, by default, when created, immediately creates one connection to the database, does it have a setting such that the connection is created only when calling acquire?
  2. In acquire, the if self.pool is None check is done twice; this is done in order not to use locking in acquire unnecessarily. Is it possible to make this code more “beautiful”? Wouldn't condition be suitable for this case?
  3. To close the pool, use the terminate method? How does it differ from close, maybe it’s worth using close?
  4. Will there be a race when the pool closes? We are closing the pool, there is no lock in acquire, will there be an error that None does not have an acquire method?
  5. Should I assign pool = None when closing a pool, that is, give the opportunity to re-open the pool? As if this is not necessary, if you had to close the pool, then there is no need for it anymore
@spumer
Copy link

spumer commented May 3, 2024

  1. Лучше наоборот отключить автоконнекты в либах и управлять этим поведением на нашем уровне. Так у нас будет возможность для всех одинаковое поведение реализовать
  2. Красиво это плохой критерий. Сделано так чтобы работало быстрее и потоки не мешали друг другу когда пул уже создан. Переделать на condition можно, но смысла нет. Он нужен только когда нам нужно упорядочить доступ к ресурсу, а при инициализации пула это лишнее.
  3. Будет, поэтому методы должны это учитывать
  4. Переоткрывать пул нас никто не обязывает, а вот подчистить за собой надо. Иначе есть риск поработать с неактуальным объектом

@kalombos kalombos added this to the v1.0.0 milestone May 3, 2024
@kalombos kalombos modified the milestones: v1.0.0, v0.11.0 May 13, 2024
@kalombos
Copy link
Collaborator Author

kalombos commented Jun 22, 2024

The pool can be connected(created) automatically only once now. If somebody close the pool he has to create it again manually otherwise he has pool is closed exception

  1. Is it possible to use the auto-connect functionality directly from pools (aiopg, aiomysql), do they have such an option? As far as I know, the aiopg pool, by default, when created, immediately creates one connection to the database, does it have a setting such that the connection is created only when calling acquire?

It is possible if forbid the min_connection option and set it as 0 by default. But it is not flexible.

  1. In acquire, the if self.pool is None check is done twice; this is done in order not to use locking in acquire unnecessarily. Is it possible to make this code more “beautiful”? Wouldn't condition be suitable for this case?

It is strange to continue acquire connection after you have closed the pool. So as i said a programmer should create the pool manually. So the double check does not need.

  1. To close the pool, use the terminate method? How does it differ from close, maybe it’s worth using close?
    It is the terminate method for a while. maybe in the future there will be a close method.
  1. Will there be a race when the pool closes? We are closing the pool, there is no lock in acquire, will there be an error that None does not have an acquire method?

It lays to a programmer to manage the pool now after he has closed it

  1. Should I assign pool = None when closing a pool, that is, give the opportunity to re-open the pool? As if this is not necessary, if you had to close the pool, then there is no need for it anymore

None is not assigned to the pool variable after closing. But it is not possible to acquire a connection after closing until you call pool.create() manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants