Reached maximum number of concurrent connections

135 views
Skip to first unread message

leon...@adimplere.com.br

unread,
Jan 4, 2017, 9:19:46 AM1/4/17
to OrientDB
Hi,

May anyone use the orientdb with java so that it closes the used connections and avoids the error "Reached maximum number of concurrent connections" ?

A simple test that I do. I'm using java8 and orientdb 2.2.14 with remote. Config sets don't work.

val poolFactory = new OPartitionedDatabasePoolFactory()
poolFactory.setMaxPoolSize(40)

val pool = poolFactory.get("remote:db.adimplere.com.br/adimplere", "admin", "ab12HTT")
val conn = pool.acquire()

try {

val query = StringBuilder.newBuilder

query.append("SELECT @this.tojson(\"fetchPlan:*:-1\") AS itens FROM Parceiro limit 1000;")

//connection.query(new OSQLSynchQuery[ODocument]("SELECT * FROM Cliente WHERE cpfCnpj=?").setFetchPlan("*:-1"))

val res = conn.query[java.util.List[ODocument]](new OSQLSynchQuery[ODocument](query.toString)).asScala.toList

val result = {
if (res.isEmpty) {
None
} else {
Some(res(0).field("itens"))
}
}

result

} finally {
conn.close()
pool.close()
poolFactory.close()
}

Oleksandr Gubchenko

unread,
Jan 4, 2017, 4:24:36 PM1/4/17
to OrientDB
This kind of error usually occurs when database.close() is not executed. The default value for the maximum number of concurrent connections is 1000, to change it use -Dnetwork.maxConcurrentSessions

Claudio Massi

unread,
Jan 5, 2017, 6:24:43 AM1/5/17
to OrientDB
This is a sample multithreaded java code (not scala) which fails with "No more resources available in pool" if you do not use db.close()

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentPool;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;

public class ThreadExample {

    private static final OSQLSynchQuery query = new OSQLSynchQuery("SELECT FROM V");
    public static void main(String[] args) {

        for (int i = 0; i < 100; i++) {
            new Thread("" + i) {
                public void run() {

                    // ODatabaseDocumentTx db = new ODatabaseDocumentTx("remote:localhost/GratefulDeadConcerts").open("admin", "admin");
                    // or use pool
                    ODatabaseDocumentTx db = ODatabaseDocumentPool.global(1,40).acquire("remote:localhost/GratefulDeadConcerts", "admin", "admin");

                    System.out.println(" 1 -- Thread: " + getName() + " running");
                    db.query(query);
                    // db.close();    // if you do not close it will fail with : No more resources available in pool (max=40)

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }.start();
        }
    }
}


com.orientechnologies.common.concur.lock.OLockException: No more resources available in pool (max=40). Requested resource: remote:localhost/GratefulDeadConcerts
    at com.orientechnologies.common.concur.resource.OResourcePool.getResource(OResourcePool.java:70)
    at com.orientechnologies.common.concur.resource.OReentrantResourcePool.getResource(OReentrantResourcePool.java:84)
    at com.orientechnologies.orient.core.db.ODatabasePoolAbstract.acquire(ODatabasePoolAbstract.java:158)
    at com.orientechnologies.orient.core.db.ODatabasePoolAbstract.acquire(ODatabasePoolAbstract.java:138)
    at com.orientechnologies.orient.core.db.ODatabasePoolBase.acquire(ODatabasePoolBase.java:128)
    at ThreadExample$1.run(ThreadExample.java:22)



Il giorno mercoledì 4 gennaio 2017 15:19:46 UTC+1, leon...@adimplere.com.br ha scritto:
Reply all
Reply to author
Forward
0 new messages