1

I set DATABASE setting like below and run Django App.

DATABASES = {
             'default': {
                         'ENGINE': 'django.db.backends.oracle',
                         'NAME': 'orcl',
                         'USER': 'smkim',
                         'PASSWORD': '1123',
                         'HOST': '168.192.15.18',
                         'PORT': '1521',
                         'CONN_MAX_AGE': 10,
                         'OPTIONS': {'threaded': True}
                         }
             }

To make sure that if Django open 10 persistent connections, I send a SQL like the below.

SELECT username FROM v$session WHERE username='SMKIM';

However, this command just returns 2 records(This is because I spawn a process, as a result two processes has one connection respectively).

Why does Django only open 2 connections even I set 10 persistent connections?

(ps. the app is using a thread pool(5) )

SangminKim
  • 8,358
  • 14
  • 69
  • 125

1 Answers1

5

'CONN_MAX_AGE' sets the age of one connection before it is closed, and not how many of them there should be, see the docs:

CONN_MAX_AGE

Default: 0

The lifetime of a database connection, in seconds. Use 0 to close database connections at the end of each request — Django’s historical behavior — and None for unlimited persistent connections.

So the connection will be opened when Django needs one and there's no other open connection, though DB can close such 'persistent' connection on it's side. See the docs section for more details.

Nikita
  • 6,101
  • 2
  • 26
  • 44
  • Thank you for your answer, I misunderstood the parameter, So is there any way to have `multiple-connection` for multiple-thread so that they try to request in parallel? – SangminKim Feb 22 '16 at 15:35
  • 1
    @asleea, as far as I remember, there's no straightforward way to specify how many persistent connection you want to have in Django. IMO, just set `CONN_MAX_AGE` at a reasonably high number and Django will do the job itself. It will open a connection on first request and keep it until it is closed on timeout on Django or DB side. For further request it will use this connection or might open a new one if required and then use several connections, but to understand when and how this will happen it is required to look in Django internals. – Nikita Feb 22 '16 at 17:23