Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 265FA200B39 for ; Sat, 25 Jun 2016 08:12:26 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 24EDF160A5A; Sat, 25 Jun 2016 06:12:26 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6C49F160A58 for ; Sat, 25 Jun 2016 08:12:25 +0200 (CEST) Received: (qmail 46559 invoked by uid 500); 25 Jun 2016 06:12:24 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 46549 invoked by uid 99); 25 Jun 2016 06:12:24 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 Jun 2016 06:12:24 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id CDB51180E73 for ; Sat, 25 Jun 2016 06:12:23 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 4.313 X-Spam-Level: **** X-Spam-Status: No, score=4.313 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=2, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_NONE=-0.0001, URI_HEX=1.313] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id fETWwQKw_kOD for ; Sat, 25 Jun 2016 06:12:21 +0000 (UTC) Received: from mbob.nabble.com (mbob.nabble.com [162.253.133.15]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 1CD235F257 for ; Sat, 25 Jun 2016 06:12:20 +0000 (UTC) Received: from msam.nabble.com (unknown [162.253.133.85]) by mbob.nabble.com (Postfix) with ESMTP id 71EFC2B1A739 for ; Fri, 24 Jun 2016 22:51:40 -0700 (PDT) Date: Fri, 24 Jun 2016 23:12:20 -0700 (MST) From: "t.schoellhorn" To: users@groovy.incubator.apache.org Message-ID: <1466835140469-5733514.post@n5.nabble.com> Subject: TemplateEngines and Out of Memory MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_739090_2114115748.1466835140470" archived-at: Sat, 25 Jun 2016 06:12:26 -0000 ------=_Part_739090_2114115748.1466835140470 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, we are using Groovy in our web-application. There we create a "lot" of dynamic String and are handling that with the TemplateEngine as we need more complex expressions there. Now we noticed that we are running into a kind of weird OOM situation. I could narrow the problem down to a quite simple reproducible example: package kos.tools.template;import java.util.HashMap;import java.util.Map;import javax.script.Bindings;import javax.script.ScriptEngine;import javax.script.ScriptEngineManager;import javax.script.SimpleBindings;public class Test { public static void main(String[] args) throws Exception { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("groovy"); String template = "step-${i}"; String groovy = "def engine = new groovy.text.GStringTemplateEngine();\n" + "def res = engine.createTemplate(template).make(bindings);\n" + "return res.toString();"; for (int i = 0; i < (10000000); i++) { Bindings vars = new SimpleBindings(); vars.put("template", template); Map templateObjects = new HashMap<>(); vars.put("bindings", templateObjects); templateObjects.put("i", i); Object res = engine.eval(groovy, vars); if (i % 100 == 0) { System.out.println("->" + res); } } } } Running that example with an Oracle JDK 1.8 and a quite small memory (just for keeping the running time small) of 32M leads to an OOM at around 2500 steps. I opened up a disussion on Stackoverflow where John Vint gave me some hints ( see here ) and it might be also a bug of the GarbageCollector itself. But in essence I think there should be a way to use the TemplateEngine in a stable way. I am happy for any suggestions and examples of how to solve this situation. Tino -- View this message in context: http://groovy.329449.n5.nabble.com/TemplateEngines-and-Out-of-Memory-tp5733514.html Sent from the Groovy Users mailing list archive at Nabble.com. ------=_Part_739090_2114115748.1466835140470 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, we are using Groovy in our web-application. There we create a "lot" of dynamic String and are handling that with the TemplateEngine as we need more complex expressions there. Now we noticed that we are running into a kind of weird OOM situation. I could narrow the problem down to a quite simple reproducible example:
package kos.tools.template;

import java.util.HashMap;
import java.util.Map;

import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.SimpleBindings;

public class Test {


	public static void main(String[] args) throws Exception {
		ScriptEngineManager factory = new ScriptEngineManager();
		ScriptEngine engine = factory.getEngineByName("groovy"); 
		
		String template = "step-${i}";
		
		String groovy = 
			"def engine = new groovy.text.GStringTemplateEngine();\n" +
			"def res = engine.createTemplate(template).make(bindings);\n" + 
			"return res.toString();";

		for (int i = 0; i < (10000000); i++) {
			Bindings vars = new SimpleBindings();
			vars.put("template", template);
			
			Map<String, Object> templateObjects = new HashMap<>();
			vars.put("bindings", templateObjects);
			templateObjects.put("i", i);

			Object res = engine.eval(groovy, vars);
			
			if (i % 100 == 0) {
				System.out.println("->" + res);
			}
		}
	}
	
}
Running that example with an Oracle JDK 1.8 and a quite small memory (just for keeping the running time small) of 32M leads to an OOM at around 2500 steps. I opened up a disussion on Stackoverflow where John Vint gave me some hints (see here) and it might be also a bug of the GarbageCollector itself. But in essence I think there should be a way to use the TemplateEngine in a stable way. I am happy for any suggestions and examples of how to solve this situation. Tino

View this message in context: TemplateEngines and Out of Memory
Sent from the Groovy Users mailing list archive at Nabble.com.
------=_Part_739090_2114115748.1466835140470--