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

JPA Java Discussion :

gc overhead limit exceeded


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Avril 2009
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 35
    Par défaut gc overhead limit exceeded
    Bonjour,

    Nous avons développer une application JPA(Eclipselink) + JSF +Richfaces.

    Mais lors de mettre notre application en production. On a remarqué qu'à chaque requête de la base, la mémoire du serveur se remplie encore plus jusqu'à arriver à une saturation d'utilisation de la mémoire 100% et ainsi on a l'exception :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    java.lang.outofmemoryerror gc overhead limit exceeded
    Il faut qu'on redémarre Tomcat pour la mémoire se libère à nouveau.

    J'ai essayé la libération du cache chaque 1minute avec JPA (Eclipselink):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    @Entity
    @Cache(type=CacheType.SOFT, // Cache everything until the JVM decides memory is low.
    		  expiry=60000, // 60 seconds
    		  coordinationType=CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS  // if cache coordination is used, only send invalidation messages.
    		)
    ou avec persistance.xml :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <property name="eclipselink.cache.shared.default" value="false"/>
    <property name="eclipselink.cache.size.default" value="0"/>
    <property name="eclipselink.cache.type.default" value="None"/>
    mais cela ne fonctionne pas.

    Je vous demande votre aide! Merci de me donner quelques idées.

    J'ai poster le même message sur la section tomcat vu que je ne sais pas si c'est un problème tomcat ou JPA(Eclipselink).

    Un collégue pense que le problème viens du garbage collector qui ne fait pas le boulot de la destruction des objets donc problème avec la JVM.

    Je suis perdu entre tout ça. Est ce un problème tomcat, jvm ou eclipselink?

    Merci à vous !

  2. #2
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    A priori c'est votre code qui est en cause. Probablement que vous gardez une référence à votre entitymanager ou à un instance JPA dans la session utilisateur, ce qui empêche cette dernière et toutes ses dépendances d'être libérée à la fin de la requête.

    Le mieux que vous ayez à faire est d'analyser votre code pour y trouver vos erreur et, si c'est trop long / pas trouvable, utilisez un profiler qui vous dira où dans votre code vous maintenez de grandes quantité de données.

    Le GC est souvent accusé bien à tord, il fait parfaitement bien son boulot. Au pire on pourrais parfois l'accuser à raison d'être lent. Mais pas d'oublier de nettoyer

  3. #3
    Membre averti
    Inscrit en
    Avril 2009
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 35
    Par défaut
    Je vous donne un exemple de mon code. pouvez-vous me dire s'il y a un truc qui manque.

    Entity Produitdp:
    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
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
     
    import java.io.Serializable;
    import java.util.Collection;
     
    import javax.persistence.*;
     
    import org.eclipse.persistence.annotations.Cache;
    import org.eclipse.persistence.annotations.CacheCoordinationType;
    import org.eclipse.persistence.annotations.CacheType;
     
    @Entity
    @Cache(type=CacheType.SOFT, // Cache everything until the JVM decides memory is low.
    		  expiry=60000, // 60 seconds
    		  size = 50,
    		  coordinationType=CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS  // if cache coordination is used, only send invalidation messages.
    		)
    @Table(name="PRODUITDP")
    public class Produitdp implements Serializable, Comparable<Produitdp> {
    	private static final long serialVersionUID = 1L;
     
    	@Id
    	@Column(name="ID_PRODUITDP", nullable=false, precision=22)
    	private String idProduitdp;
     
    	@Column(nullable=false, length=100)
    	private String nom;
     
    	@Column(length=500)
    	private String commentaire;
     
    	@Column(nullable=false, precision=1)
    	private String visible;
     
    	@JoinColumn(name="DEVTEAM_ID")
    	private Devteam devteam;
     
    	@Column(name="ID_PRODDPCAT", precision=22)
    	private String idProddpcat;
     
    	@ManyToOne
    	@JoinColumn(name="ID_PRODUIT")
    	private Produit produit;
     
    	@ManyToOne
    	@JoinColumn(name="ID_PLACE")
    	private Place place;
     
    	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY, mappedBy="produitdp")
    	@JoinColumn(name="ID_PRODUITDP")
    	private Collection<Configfile> configfiles;
     
    	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY, mappedBy="produitdp")
    	@JoinColumn(name="ID_PRODUITDP")
    	private Collection<Version> versions;
     
    	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY, mappedBy="produitdp")
    	@JoinColumn(name="ID_PRODUITDP")
    	private Collection<ProduitdpOs> produitdpOss;
     
        public Produitdp() {
        }
     
     
     
    	public Collection<Configfile> getConfigfiles() {
    		return configfiles;
    	}
     
    	public void setConfigfiles(Collection<Configfile> configfiles) {
    		this.configfiles = configfiles;
    	}
     
     
    	public String getCommentaire() {
    		return this.commentaire;
    	}
     
    	public void setCommentaire(String commentaire) {
    		this.commentaire = commentaire;
    	}
     
    	public String getIdProddpcat() {
    		return this.idProddpcat;
    	}
     
    	public void setIdProddpcat(String idProddpcat) {
    		this.idProddpcat = idProddpcat;
    	}
     
    	public String getIdProduitdp() {
    		return this.idProduitdp;
    	}
     
    	public void setIdProduitdp(String idProduitdp) {
    		this.idProduitdp = idProduitdp;
    	}
     
    	public String getNom() {
    		return this.nom;
    	}
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	public String getVisible() {
    		return this.visible;
    	}
     
    	public void setVisible(String visible) {
    		this.visible = visible;
    	}
     
    	public Collection<Version> getVersions() {
    		return versions;
    	}
     
    	public void setVersions(Collection<Version> versions) {
    		this.versions = versions;
    	}
     
    	public int compareTo(Produitdp o) {
    		return(this.getNom().compareTo(o.getNom()));
    	}
     
    	public Produit getProduit() {
    		return produit;
    	}
     
    	public void setProduit(Produit produit) {
    		this.produit = produit;
    	}
     
    	public Place getPlace() {
    		return place;
    	}
     
    	public void setPlace(Place place) {
    		this.place = place;
    	}
     
    	public Devteam getDevteam() {
    		return devteam;
    	}
     
    	public void setDevteam(Devteam devteam) {
    		this.devteam = devteam;
    	}
     
    	public Collection<ProduitdpOs> getProduitdpOss() {
    		return produitdpOss;
    	}
     
    	public void setProduitdpOss(Collection<ProduitdpOs> produitdpOss) {
    		this.produitdpOss = produitdpOss;
    	}
     
    }

    Entity : Version :
    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
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
     
     
    import java.io.Serializable;
    import javax.persistence.*;
     
    import org.eclipse.persistence.annotations.Cache;
    import org.eclipse.persistence.annotations.CacheCoordinationType;
    import org.eclipse.persistence.annotations.CacheType;
     
     
    import java.util.Collection;
    import java.util.Date;
     
     
    @Entity
    @Cache(type=CacheType.SOFT, // Cache everything until the JVM decides memory is low.
    		  expiry=60000, // 60 seconds
    		  coordinationType=CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS  // if cache coordination is used, only send invalidation messages.
    		)
    @Table(name="VERSION")
    public class Version implements Serializable, Comparable<Version> {
    	private static final long serialVersionUID = 1L;
     
    	@Id
    	@SequenceGenerator(name="VERSION_IDVERSION_GENERATOR", sequenceName="ID_VERSION",allocationSize=1)
    	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="VERSION_IDVERSION_GENERATOR")
    	@Column(name="ID_VERSION", unique=true, nullable=false, precision=22)
    	private long idVersion;
     
    	@Column(length=500)
    	private String commentaire;
     
        @Temporal( TemporalType.DATE)
    	@Column(name="DATE_STATUT")
    	private Date dateStatut;
     
    	@Column(nullable=false, precision=1)
    	private String intradev;
     
    	@Column(length=20)
    	private String numcorrection;
     
    	@Column(nullable=false, length=100)
    	private String numero;
     
    	@Column(length=20)
    	private String numevolution;
     
    	@Column(nullable=false, length=20)
    	private String numgeneration;
     
    	@Column(precision=22)
    	private String numintradev;
     
    	@Column(length=20)
    	private String nummajeur;
     
    	@Column(precision=22)
    	private String project;
     
    	@JoinColumn(name="ID_STATUT")
    	private Statut statut;
     
    	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY, mappedBy="version")
    	@JoinColumn(name="ID_VERSION")
    	private Collection<Fichelivraison> fichelivraisons;
     
    	@ManyToOne
    	@JoinColumn(name="ID_PRODUITDP")
    	private Produitdp produitdp;
     
        public Version() {
        }
     
    	public long getIdVersion() {
    		return this.idVersion;
    	}
     
    	public void setIdVersion(long idVersion) {
    		this.idVersion = idVersion;
    	}
     
    	public String getCommentaire() {
    		return this.commentaire;
    	}
     
    	public void setCommentaire(String commentaire) {
    		this.commentaire = commentaire;
    	}
     
    	public Date getDateStatut() {
    		return this.dateStatut;
    	}
     
    	public void setDateStatut(Date dateStatut) {
    		this.dateStatut = dateStatut;
    	}
     
    	public String getIntradev() {
    		return this.intradev;
    	}
     
    	public void setIntradev(String intradev) {
    		this.intradev = intradev;
    	}
     
    	public String getNumcorrection() {
    		return this.numcorrection;
    	}
     
    	public void setNumcorrection(String numcorrection) {
    		this.numcorrection = numcorrection;
    	}
     
    	public String getNumero() {
    		return this.numero;
    	}
     
    	public void setNumero(String numero) {
    		this.numero = numero;
    	}
     
    	public String getNumevolution() {
    		return this.numevolution;
    	}
     
    	public void setNumevolution(String numevolution) {
    		this.numevolution = numevolution;
    	}
     
    	public String getNumgeneration() {
    		return this.numgeneration;
    	}
     
    	public void setNumgeneration(String numgeneration) {
    		this.numgeneration = numgeneration;
    	}
     
    	public String getNumintradev() {
    		return this.numintradev;
    	}
     
    	public void setNumintradev(String numintradev) {
    		this.numintradev = numintradev;
    	}
     
    	public String getNummajeur() {
    		return this.nummajeur;
    	}
     
    	public void setNummajeur(String nummajeur) {
    		this.nummajeur = nummajeur;
    	}
     
    	public String getProject() {
    		return this.project;
    	}
     
    	public void setProject(String project) {
    		this.project = project;
    	}
     
    	public String getKey()
    	{
    		return(Long.toString(getIdVersion()));
    	}
     
    	public Collection<Fichelivraison> getFichelivraisons() {
    		return fichelivraisons;
    	}
     
    	public void setFichelivraisons(Collection<Fichelivraison> fichelivraisons) {
    		this.fichelivraisons = fichelivraisons;
    	}
     
    	public Produitdp getProduitdp() {
    		return produitdp;
    	}
     
    	public void setProduitdp(Produitdp produitdp) {
    		this.produitdp = produitdp;
    	}
     
    	public Statut getStatut() {
    		return statut;
    	}
     
    	public void setStatut(Statut statut) {
    		this.statut = statut;
    	}
     
    	public int compareTo(Version o) {
    		// TODO Auto-generated method stub
    		return (this.getNumero().compareTo(o.getNumero()));
    	}
     
    }
    Produitdp Dao

    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
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
     
     
    import java.util.List;
    import javax.persistence.EntityManager;
    import javax.persistence.NoResultException;
    import javax.persistence.Persistence;
     
     
    public class ProduitdpDao {
    	private static final String JPA_UNIT_NAME = "exemple";
    	private EntityManager entityManager;
     
     
    	//READ
    	@SuppressWarnings("unchecked")
    	public List<Produitdp> selectAll() {
    		try{
    		List<Produitdp> produitdps = getEntityManager().createQuery(
    				"select p from Produitdp p where p.visible='1' order by p.nom").getResultList();
    		return produitdps;
    		 } catch(NoResultException e) {
    		        return null;
    		    }
    	}
     
    	//CREATE
    	public Produitdp insert(Produitdp u) {
    		getEntityManager().getTransaction().begin();
    		getEntityManager().persist(u);
    		getEntityManager().getTransaction().commit();
    		return u;
    	}
     
    	//UPDATE
    	public Produitdp update(Produitdp u) {
    		getEntityManager().getTransaction().begin();
    		u = getEntityManager().merge(u);
    		getEntityManager().getTransaction().commit();
    		return u;
    	}
     
    	//DELETE
    	public void delete(Produitdp u) {
    		getEntityManager().getTransaction().begin();
    		u = getEntityManager().merge(u);
    		getEntityManager().remove(u);
    		getEntityManager().getTransaction().commit();
    	}
     
    	//FINDBYID
    	public Produitdp findbyId(String value){
    		Produitdp p=(Produitdp) getEntityManager().createQuery("select p from Produitdp p where p.idProduitdp='"+value+"'").getSingleResult();
    		return(p);
    	}
     
    	//EntityManager
    	protected EntityManager getEntityManager() {
    		if (entityManager == null) {
    			entityManager = Persistence.createEntityManagerFactory(
    					JPA_UNIT_NAME).createEntityManager();
    		}
    		return entityManager;
    	}
     
    }
    Bean :

    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
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
     
     
    import java.util.ArrayList;
    import java.util.List;
     
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ViewScoped;
    import javax.faces.event.ValueChangeEvent;
    import javax.faces.model.SelectItem;
     
    @ManagedBean(name = "controlBean")
    @ViewScoped
    public class ControlBean {
     
    	String valeur;
     
    	private List<SelectItem> produitdps;
    	private List<Version> versions = new ArrayList<Version>();
    	private Produitdp selectedItem1=null;
    	ProduitdpDao produitdpDao = new ProduitdpDao();
    	VersionDao versionDao = new VersionDao();
    	private int current=1;
     
    	{
    		fillProduitdps();
    	}
     
    	private void fillProduitdps() {
    		produitdps = new ArrayList<SelectItem>();
    		for (Produitdp Pdp : produitdpDao.selectAll()) {
    			produitdps.add(new SelectItem(Pdp, Pdp.getNom()));
    		}
    		current+=50;
     
    	}
     
    	public void produitdpChanged(ValueChangeEvent event) {
    		Produitdp p = (Produitdp) event.getNewValue();
    		versions = versionDao.findByIdProduitdpPageable(p.getIdProduitdp(),0,50);
    	}
     
     
    	public void showMoreResult(){
    		if(selectedItem1!=null){
    		versions.addAll(versionDao.findByIdProduitdpPageable(selectedItem1.getIdProduitdp(),current,50));
    		current+=50;
    		}
    	}
     
    	public String getValeur() {
    		return valeur;
    	}
     
    	public void setValeur(String valeur) {
    		this.valeur = valeur;
    	}
     
    	public List<Version> getVersions() {
    		return versions;
    	}
     
    	public void setVersions(List<Version> versions) {
    		this.versions = versions;
    	}
     
    	public List<SelectItem> getProduitdps() {
    		return produitdps;
    	}
     
    	public void setProduitdps(List<SelectItem> produitdps) {
    		this.produitdps = produitdps;
    	}
     
    	public Produitdp getSelectedItem1() {
    		return selectedItem1;
    	}
     
    	public void setSelectedItem1(Produitdp selectedItem1) {
    		this.selectedItem1 = selectedItem1;
    	}
     
    }

    Ce code est simple, il affiche toutes les versions d'un produitdp donné après sélection.

    Est ce qu'il y a un truc qui manque dans mon code.

    Merci de bien vouloir vérifier avec moi. Sinon, je vais me renseigner un peu sur le profiler et essayer de trouver une solution.

  4. #4
    Membre expérimenté Avatar de Shinzul
    Homme Profil pro
    Lecteur assidu de code source
    Inscrit en
    Janvier 2008
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Lecteur assidu de code source
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2008
    Messages : 174
    Par défaut
    En lisant comme ca il y a quelque chose qui me tracasse un peu.

    C'est cette initialisation des Dao dans le ManagedBean. Chaque Dao est donc instancié un nombre de fois égal à son utilisation dans des ManagedBean. De plus à la vu du scope de l'exemple, les Dao sont ré-instancier à chaque accès à cette page.

    Après je ne saurais pas dire comme ca pourquoi il n'y a pas de libération de la mémoire.

  5. #5
    Membre averti
    Inscrit en
    Avril 2009
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 35
    Par défaut
    Donc à votre avis, qu'est ce que vous me conseillez de faire? je devrai enlever l'initialisation du Dao dans le managed bean et les mettre dans les fonctions?

  6. #6
    Membre expérimenté Avatar de Shinzul
    Homme Profil pro
    Lecteur assidu de code source
    Inscrit en
    Janvier 2008
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Lecteur assidu de code source
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2008
    Messages : 174
    Par défaut
    Après une deuxième relecture de ton code, je viens de voir quelque chose qui pourrais être à la base de ton problème.

    Tes EntityManager ne sont jamais close.

    Je ne sais pas si le fait de ne pas close un EntityManager lorsqu'il est créer à la main peut le faire maintenir dans la mémoire de l'application par un lien entre la factory et lui même.

    Je te dirai donc d'essayer déjà de close des EntityManager.

Discussions similaires

  1. java.lang.OutOfMemoryError: GC overhead limit exceeded
    Par recherche888 dans le forum MATLAB
    Réponses: 4
    Dernier message: 20/03/2012, 13h25
  2. Faible performance Tomcat "GC overhead limit exceeded"
    Par questionneuse dans le forum Tomcat et TomEE
    Réponses: 17
    Dernier message: 14/09/2011, 15h19
  3. Réponses: 3
    Dernier message: 01/04/2011, 13h55
  4. java.lang.OutOfMemorryError : GC overhead limit exceeded
    Par Yozol dans le forum Développement de jobs
    Réponses: 2
    Dernier message: 06/10/2010, 11h37
  5. Connection limit exceeded for non-superusers
    Par bitou dans le forum PostgreSQL
    Réponses: 4
    Dernier message: 10/05/2007, 03h37

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