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

Excessive memory consumption w/SuperServer when large number of connections opened [CORE4857] #5153

Closed
firebird-automations opened this issue Jul 3, 2015 · 17 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @pavel-zotov

Relate to CORE3633

Attachments:
fb-memory-consumation.PNG

FB version: WI-T3.0.0.31916

Config:

AuthClient = Legacy_Auth,Srp,Win_Sspi
AuthServer = Legacy_Auth,Srp
FileSystemCacheThreshold = 65536K
LockHashSlots = 22111
MaxUnflushedWrites = -1
MaxUnflushedWriteTime = -1
MaxUserTraceLogSize = 99999
RemoteServicePort = 3333
TempCacheLimit = 2147483647
TempDirectories = c:\temp
UserManager = Legacy_UserManager
WireCrypt = Disabled

NOTE: using architecture is SuperServer.

Extremely huge memory consumption was explored during developing test on Python for core-4439, while trying to establish 2000 attachments:
{
'id': 'bugs.core_4439',
'qmid': '',
'tracker_id': 'CORE4439',
'title': 'Raise the 1024 connections limit (FD_SETSIZE) on Windows SS/SC',
'description': '',
'min_versions': None,
'versions': [
{
'firebird_version': '3.0',
'platform': 'All',
'init_script':
"""
""",
'test_type': 'Python',
'test_script': """db_conn.close()
i = 1
while i <= 2000:
runexpr='c%i = kdb.connect(dsn=dsn,user=user_name,password=user_password)' % i
exec runexpr
print ('Established connection, sequential N=',i)
i += 1
""",
'expected_stdout':
"""
"""
}
]
}

The same can be obtained using following java class:

=== begin ===
import java.sql.*;
import org.firebirdsql.jdbc.*;

public class MultipleAttaches {
private static final String URL = "jdbc:firebirdsql://localhost:3333/e30";
private static final String USR = "SYSDBA";
private static final String PSW = "masterke";
public static void main(String[] args) {

FirebirdConnection\[\] ca = new FirebirdConnection\[ 2000 \];
long ms;
for\(int i=0; i < ca\.length; i\+\+ \) \{
  try \{
     ms = System\.currentTimeMillis\(\);
     ca\[i\] = \(FirebirdConnection\)java\.sql\.DriverManager\.getConnection\(URL, USR, PSW\);
     System\.out\.printf\( "\\nEtsablished connection %4d at %6d ms", 1\+i, System\.currentTimeMillis\(\) \- ms \);
  \}
  catch \(Exception x\) \{
    x\.printStackTrace\(\);
    System\.exit\(1\); \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \[ 1 \]
  \}
\}

try \{ Thread\.sleep\(1000000\); \} catch \(InterruptedException e\) \{ \}

}
}
=== end ===

Steps to reproduce (assuming that JRE was installed):
1) correct values of constants URL, USR and PSW to yours.
2) download jaybird-full-2.x.x.jar and save it to the c:\temp\
3) create environment variable with the name = CLASSPATH and value = .;c:\temp\* // note about leading dot and trailing asterisk
4) compile: javac MultipleAttaches.java // output should be empty
5) running: java MultipleAttaches).

When I run this class, I get:

Etsablished connection 1 at 719 ms
Etsablished connection 2 at 15 ms
Etsablished connection 3 at 31 ms
Etsablished connection 4 at 0 ms
. . .
Etsablished connection 1524 at 31 ms
Etsablished connection 1525 at 31 ms
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544430. unable to allocate memory from o
perating system
at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:123)
at org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:126)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at MultipleAttaches.main(MultipleAttaches.java:20)
Caused by: org.firebirdsql.gds.GDSException: unable to allocate memory from operating system
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.readStatusVector(AbstractJavaGDSImpl.java:2092)
. . .

There are 2 GB memory on my machine (OS = Win XP), all not-necessary applications and services have been terminated before this test was launched.
When exception occurs, FB consumes about 1.8 Gb memory - see attached screenshot.

firebird.log will contain:

CSPROG Fri Jul 03 20:29:39 2015
INET/inet_error: read errno = 10054

CSPROG Fri Jul 03 20:29:39 2015
INET/inet_error: read errno = 10054

CSPROG Fri Jul 03 20:29:39 2015
INET/inet_error: read errno = 10054

CSPROG Fri Jul 03 20:29:39 2015
Operating system call _beginthreadex failed. Error code 8

CSPROG Fri Jul 03 20:29:39 2015
INET/inet_error: read errno = 10054
. . .

The question is: what forces FB to consume so much memory when only new attachments are done (and no any actions within them) ?

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

Attachment: fb-memory-consumation.PNG [ 12771 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: Sean Leyne (seanleyne)

summary: Excessive memory consumation in SuperServer 3.0 while establishing multiple attachments. Memory can be not released if output of abend messages is interrupted by Ctrl-C => Excessive memory consumption w/SuperServer when large number of connections opened. Memory is not released if output of abend messages is interrupted by Ctrl-C

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

It seems this case is really 2 separate issues, which should be separate cases on their own.

1- Why does a connection use so much memory (ie. why do 1500 connection use 1.8GB of RAM)? {BTW, what is the db page cache setting?}

2- Memory is not released if "output" is interrupted.

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

> BTW, what is the db page cache setting

Not specified (neither in firebird.conf nor in database header) - so, it's default, 2048.

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

PS. Moved part of origin text (about not-releasing memory after interrupting output by Ctrl-C) to the new ticket, core-4858.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

description: FB version: WI-T3.0.0.31916

Config:

AuthClient = Legacy_Auth,Srp,Win_Sspi
AuthServer = Legacy_Auth,Srp
FileSystemCacheThreshold = 65536K
LockHashSlots = 22111
MaxUnflushedWrites = -1
MaxUnflushedWriteTime = -1
MaxUserTraceLogSize = 99999
RemoteServicePort = 3333
TempCacheLimit = 2147483647
TempDirectories = c:\temp
UserManager = Legacy_UserManager
WireCrypt = Disabled

NOTE: using architecture is SuperServer.

Extremely huge memory consumption was explored during developing test on Python for core-4439, while trying to establish 2000 attachments:
{
'id': 'bugs.core_4439',
'qmid': '',
'tracker_id': 'CORE4439',
'title': 'Raise the 1024 connections limit (FD_SETSIZE) on Windows SS/SC',
'description': '',
'min_versions': None,
'versions': [
{
'firebird_version': '3.0',
'platform': 'All',
'init_script':
"""
""",
'test_type': 'Python',
'test_script': """db_conn.close()
i = 1
while i <= 2000:
runexpr='c%i = kdb.connect(dsn=dsn,user=user_name,password=user_password)' % i
exec runexpr
print ('Established connection, sequential N=',i)
i += 1
""",
'expected_stdout':
"""
"""
}
]
}

The same can be obtained using following java class:

=== begin ===
import java.sql.*;
import org.firebirdsql.jdbc.*;

public class MultipleAttaches {
private static final String URL = "jdbc:firebirdsql://localhost:3333/e30";
private static final String USR = "SYSDBA";
private static final String PSW = "masterke";
public static void main(String[] args) {

FirebirdConnection\[\] ca = new FirebirdConnection\[ 2000 \];
long ms;
for\(int i=0; i < ca\.length; i\+\+ \) \{
  try \{
     ms = System\.currentTimeMillis\(\);
     ca\[i\] = \(FirebirdConnection\)java\.sql\.DriverManager\.getConnection\(URL, USR, PSW\);
     System\.out\.printf\( "\\nEtsablished connection %4d at %6d ms", 1\+i, System\.currentTimeMillis\(\) \- ms \);
  \}
  catch \(Exception x\) \{
    x\.printStackTrace\(\);
    System\.exit\(1\); \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \[ 1 \]
  \}
\}

try \{ Thread\.sleep\(1000000\); \} catch \(InterruptedException e\) \{ \}

}
}
=== end ===

Steps to reproduce (assuming that JRE was installed):
1) correct values of constants URL, USR and PSW to yours.
2) download jaybird-full-2.x.x.jar and save it to the c:\temp\
3) create environment variable with the name = CLASSPATH and value = .;c:\temp\* // note about leading dot and trailing asterisk
4) compile: javac MultipleAttaches.java // output should be empty
5) running: java MultipleAttaches).

When I run this class, I get:

Etsablished connection 1 at 719 ms
Etsablished connection 2 at 15 ms
Etsablished connection 3 at 31 ms
Etsablished connection 4 at 0 ms
. . .
Etsablished connection 1524 at 31 ms
Etsablished connection 1525 at 31 ms
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544430. unable to allocate memory from o
perating system
at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:123)
at org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:126)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at MultipleAttaches.main(MultipleAttaches.java:20)
Caused by: org.firebirdsql.gds.GDSException: unable to allocate memory from operating system
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.readStatusVector(AbstractJavaGDSImpl.java:2092)
. . .

There are 2 GB memory on my machine (OS = Win XP), all not-necessary applications and services have been terminated before this test was launched.
When exception occurs, FB consumes about 1.8 Gb memory - see attached screenshot.

firebird.log will contain:

CSPROG Fri Jul 03 20:29:39 2015
INET/inet_error: read errno = 10054

CSPROG Fri Jul 03 20:29:39 2015
INET/inet_error: read errno = 10054

CSPROG Fri Jul 03 20:29:39 2015
INET/inet_error: read errno = 10054

CSPROG Fri Jul 03 20:29:39 2015
Operating system call _beginthreadex failed. Error code 8

CSPROG Fri Jul 03 20:29:39 2015
INET/inet_error: read errno = 10054
. . .

The question is: what forces FB to consume so much memory when only new attachments are done (and no any actions within them) ?

PS. Furthermore: if I comment statement:

System.exit(1); --------------------------------- [ 1 ]

-- and run this class again, then bulk of messages about unable to allocate memory appear. If I interrupt this output, than FB does not release memory, and no further attachments can be done to that service.

=>

FB version: WI-T3.0.0.31916

Config:

AuthClient = Legacy_Auth,Srp,Win_Sspi
AuthServer = Legacy_Auth,Srp
FileSystemCacheThreshold = 65536K
LockHashSlots = 22111
MaxUnflushedWrites = -1
MaxUnflushedWriteTime = -1
MaxUserTraceLogSize = 99999
RemoteServicePort = 3333
TempCacheLimit = 2147483647
TempDirectories = c:\temp
UserManager = Legacy_UserManager
WireCrypt = Disabled

NOTE: using architecture is SuperServer.

Extremely huge memory consumption was explored during developing test on Python for core-4439, while trying to establish 2000 attachments:
{
'id': 'bugs.core_4439',
'qmid': '',
'tracker_id': 'CORE4439',
'title': 'Raise the 1024 connections limit (FD_SETSIZE) on Windows SS/SC',
'description': '',
'min_versions': None,
'versions': [
{
'firebird_version': '3.0',
'platform': 'All',
'init_script':
"""
""",
'test_type': 'Python',
'test_script': """db_conn.close()
i = 1
while i <= 2000:
runexpr='c%i = kdb.connect(dsn=dsn,user=user_name,password=user_password)' % i
exec runexpr
print ('Established connection, sequential N=',i)
i += 1
""",
'expected_stdout':
"""
"""
}
]
}

The same can be obtained using following java class:

=== begin ===
import java.sql.*;
import org.firebirdsql.jdbc.*;

public class MultipleAttaches {
private static final String URL = "jdbc:firebirdsql://localhost:3333/e30";
private static final String USR = "SYSDBA";
private static final String PSW = "masterke";
public static void main(String[] args) {

FirebirdConnection\[\] ca = new FirebirdConnection\[ 2000 \];
long ms;
for\(int i=0; i < ca\.length; i\+\+ \) \{
  try \{
     ms = System\.currentTimeMillis\(\);
     ca\[i\] = \(FirebirdConnection\)java\.sql\.DriverManager\.getConnection\(URL, USR, PSW\);
     System\.out\.printf\( "\\nEtsablished connection %4d at %6d ms", 1\+i, System\.currentTimeMillis\(\) \- ms \);
  \}
  catch \(Exception x\) \{
    x\.printStackTrace\(\);
    System\.exit\(1\); \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \[ 1 \]
  \}
\}

try \{ Thread\.sleep\(1000000\); \} catch \(InterruptedException e\) \{ \}

}
}
=== end ===

Steps to reproduce (assuming that JRE was installed):
1) correct values of constants URL, USR and PSW to yours.
2) download jaybird-full-2.x.x.jar and save it to the c:\temp\
3) create environment variable with the name = CLASSPATH and value = .;c:\temp\* // note about leading dot and trailing asterisk
4) compile: javac MultipleAttaches.java // output should be empty
5) running: java MultipleAttaches).

When I run this class, I get:

Etsablished connection 1 at 719 ms
Etsablished connection 2 at 15 ms
Etsablished connection 3 at 31 ms
Etsablished connection 4 at 0 ms
. . .
Etsablished connection 1524 at 31 ms
Etsablished connection 1525 at 31 ms
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544430. unable to allocate memory from o
perating system
at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:123)
at org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:126)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at MultipleAttaches.main(MultipleAttaches.java:20)
Caused by: org.firebirdsql.gds.GDSException: unable to allocate memory from operating system
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.readStatusVector(AbstractJavaGDSImpl.java:2092)
. . .

There are 2 GB memory on my machine (OS = Win XP), all not-necessary applications and services have been terminated before this test was launched.
When exception occurs, FB consumes about 1.8 Gb memory - see attached screenshot.

firebird.log will contain:

CSPROG Fri Jul 03 20:29:39 2015
INET/inet_error: read errno = 10054

CSPROG Fri Jul 03 20:29:39 2015
INET/inet_error: read errno = 10054

CSPROG Fri Jul 03 20:29:39 2015
INET/inet_error: read errno = 10054

CSPROG Fri Jul 03 20:29:39 2015
Operating system call _beginthreadex failed. Error code 8

CSPROG Fri Jul 03 20:29:39 2015
INET/inet_error: read errno = 10054
. . .

The question is: what forces FB to consume so much memory when only new attachments are done (and no any actions within them) ?

@firebird-automations
Copy link
Collaborator Author

Modified by: Sean Leyne (seanleyne)

summary: Excessive memory consumption w/SuperServer when large number of connections opened. Memory is not released if output of abend messages is interrupted by Ctrl-C => Excessive memory consumption w/SuperServer when large number of connections opened

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Fix Version: 3.0 RC 1 [ 10584 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

assignee: Alexander Peshkov [ alexpeshkoff ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

Link: This issue is related to CORE3633 [ CORE3633 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

Link: This issue is related to CORE3633 [ CORE3633 ] =>

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

Link: This issue relate to CORE3633 [ CORE3633 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Fix Version: 3.0.0 [ 10048 ]

Fix Version: 3.0 RC 1 [ 10584 ] =>

@firebird-automations
Copy link
Collaborator Author

Commented by: @AlexPeshkoff

3.0 SS is using per-attachment metadata cache (unlike SS in all previous releases). Therefore memory consumption per-attachment is much bigger than it was before - though certainly smaller than in SC.

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Won't Fix [ 2 ]

Fix Version: 4.0 Alpha 1 [ 10731 ]

Fix Version: 3.0.0 [ 10048 ] =>

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Fix Version: 4.0 Alpha 1 [ 10731 ] =>

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