IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

NoSQL Discussion :

[MongoDB][Java] Fermeture automatique des connexions


Sujet :

NoSQL

  1. #1
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2007
    Messages
    387
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2007
    Messages : 387
    Points : 301
    Points
    301
    Par défaut [MongoDB][Java] Fermeture automatique des connexions
    Bonjour,

    Je suis en train de mettre en place MongoDB dans une application et une donnée m'ennuie :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    Mon Sep  9 11:34:07.336 [initandlisten] connection accepted from 127.0.0.1:47409 #11 (1 connection now open)
    Mon Sep  9 11:34:13.451 [initandlisten] connection accepted from 127.0.0.1:47414 #13 (2 connections now open)
    Mon Sep  9 11:34:15.377 [initandlisten] connection accepted from 127.0.0.1:47415 #14 (3 connections now open)
    Mon Sep  9 11:35:26.508 [initandlisten] connection accepted from 127.0.0.1:47420 #16 (4 connections now open)
    Mon Sep  9 11:35:31.400 [initandlisten] connection accepted from 127.0.0.1:47421 #17 (5 connections now open)
    Mon Sep  9 11:36:37.089 [initandlisten] connection accepted from 127.0.0.1:47426 #18 (6 connections now open)
    Mon Sep  9 11:36:38.419 [initandlisten] connection accepted from 127.0.0.1:47427 #19 (7 connections now open)
    Mon Sep  9 11:38:02.152 [initandlisten] connection accepted from 127.0.0.1:47432 #20 (8 connections now open)
    Mon Sep  9 11:38:09.243 [initandlisten] connection accepted from 127.0.0.1:47433 #21 (9 connections now open)
    Mon Sep  9 11:39:15.769 [initandlisten] connection accepted from 127.0.0.1:47438 #22 (10 connections now open)
    Mon Sep  9 11:39:18.539 [initandlisten] connection accepted from 127.0.0.1:47439 #23 (11 connections now open)
    Mon Sep  9 11:40:23.533 [initandlisten] connection accepted from 127.0.0.1:47449 #24 (12 connections now open)
    Mon Sep  9 11:41:31.842 [initandlisten] connection accepted from 127.0.0.1:47454 #25 (13 connections now open)
    Mon Sep  9 11:42:39.244 [initandlisten] connection accepted from 127.0.0.1:47459 #26 (14 connections now open)
    Mon Sep  9 11:43:47.683 [initandlisten] connection accepted from 127.0.0.1:47464 #27 (15 connections now open)
    Mon Sep  9 11:44:56.991 [initandlisten] connection accepted from 127.0.0.1:47469 #28 (16 connections now open)
    Mon Sep  9 11:46:01.443 [initandlisten] connection accepted from 127.0.0.1:47481 #29 (17 connections now open)
    Il semblerait que les connections ne soient jamais relâchées.

    Est-il possible de mettre un timeout sur les connexions ?

    Voici ma configuration actuelle (SpringConfig.xml) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
     
    <?xml version="1.0" encoding="UTF-8"?>
     
    <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:context="http://www.springframework.org/schema/context"
              xmlns:mongo="http://www.springframework.org/schema/data/mongo"
              xsi:schemaLocation=
              "http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-3.0.xsd
              http://www.springframework.org/schema/data/mongo
              http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
              http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
     
    	<mongo:mongo host="mongodb.monserveur.local" port="27017" >
    	<mongo:options connections-per-host="10"
    		threads-allowed-to-block-for-connection-multiplier="4"
    		connect-timeout="1000" 
    		max-wait-time="1500"
    		auto-connect-retry="true" 
    		socket-keep-alive="true"
    		socket-timeout="60000" 
    		slave-ok="true"
    		write-number="1" 
    		write-timeout="0" 
    		write-fsync="false" />
    	</mongo:mongo>
     
    	<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    		<constructor-arg ref="mongo" />
    		<constructor-arg name="databaseName" value="mabase" />
    	</bean>
     
    </beans>
    Appelé par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    ApplicationContext context = new GenericXmlApplicationContext("SpringConfig.xml");
    MongoOperations mongoOperation = (MongoOperations) m_context.getBean("mongoTemplate");
    J'ai trouvé sur cette page (http://docs.mongodb.org/manual/refer...ection-string/ la propriété "maxIdleTimeMS" mais je ne sais pas comment la mettre en place.

    Merci d'avance.

    NB : je travaille sous Ubuntu.

  2. #2
    Rédacteur

    Homme Profil pro
    Geek entrepreneur
    Inscrit en
    Novembre 2004
    Messages
    1 224
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Geek entrepreneur

    Informations forums :
    Inscription : Novembre 2004
    Messages : 1 224
    Points : 2 373
    Points
    2 373
    Par défaut
    Personnellement j'utilise Jongo et je paramètre la taille du pool via l'url de connexion.

    Mais je vois dans la XSD qu'en principe c'est le parametre connection-per-host qui donne la taille max du pool :

    http://www.springframework.org/schem...ring-mongo.xsd

    Et sinon la doc complète :

    http://static.springsource.org/sprin...eference/html/

  3. #3
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2007
    Messages
    387
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2007
    Messages : 387
    Points : 301
    Points
    301
    Par défaut
    Bonjour,

    Le "connections-per-host" permet de déterminer un pool de connexion disponible pour chaque host : ce pool s'incrémente à chaque appel pour arriver à la limite.
    Le problème est de savoir si ce pool est valide "à vie", et le cas échéant, comment cela se passe quand une connexion n'est plus valide ? (erreur, nouvelle création sans problème)

    Également, un élément me gène :
    J'ai des "services" JSON qui accède à la BDD, ils sont limités à 10 par host -> cela fonctionne.
    J'ai 5 processus qui scannent en continue la BDD et qui sont limités à 100 par host -> ne fonctionne pas, j'ai 981 connexions créées depuis hier.

    Voici les options actuelles :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    <mongo:options connections-per-host="100"
    		threads-allowed-to-block-for-connection-multiplier="5"
    		connect-timeout="1000" 
    		max-wait-time="1500"
    		auto-connect-retry="true" 
    		socket-keep-alive="false"
    		socket-timeout="10000" 
    		slave-ok="true"
    		write-number="1" 
    		write-timeout="0" 
    		write-fsync="false" />
    	</mongo:mongo>

    Ce problème est-il connu ?

    Cordialement.

Discussions similaires

  1. Gestion automatique des connexions sous MySQL
    Par aaron dans le forum Administration
    Réponses: 1
    Dernier message: 16/09/2010, 13h11
  2. Réponses: 5
    Dernier message: 30/09/2009, 18h40
  3. gestionnaire automatique des accesseurs en java
    Par mokh7 dans le forum Langage
    Réponses: 3
    Dernier message: 26/05/2008, 13h03
  4. [CS3] Fermeture automatique des balises
    Par Aspic dans le forum Dreamweaver
    Réponses: 6
    Dernier message: 03/02/2008, 00h26
  5. "Détection automatique des paramètre proxy" en Java ?
    Par filc0 dans le forum Général Java
    Réponses: 9
    Dernier message: 15/01/2008, 22h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo