Apache camel Camel 2.18流缓存:java.lang.OutOfMemoryError:java堆空间
我正在使用Camel 2.18和java8。下面是一些路由代码。我将此类JSON发布到此服务:Apache camel Camel 2.18流缓存:java.lang.OutOfMemoryError:java堆空间,apache-camel,Apache Camel,我正在使用Camel 2.18和java8。下面是一些路由代码。我将此类JSON发布到此服务: { "bigField": "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest", "sma
{
"bigField": "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest",
"smallField": "234"
}
问题是,这个大字段非常大,可能是256MB。这就是为什么我考虑在Camel中使用流缓存:不确定是否可以在我的场景中应用它?我的理解是,这种机制应该一点一点地将流存储在磁盘上?我创建了/tmp/cachedir,看到了Camel是如何创建和删除一些临时文件的
6:15:23.505 [qtp422330142-21 - /myservice/v1/oper] DEBUG org.apache.camel.util.FileUtil - Retrying attempt 0 to delete file: /tmp/cachedir/cos7138988885969104934.tmp
16:15:23.505 [qtp422330142-21 - /myservice/v1/oper] DEBUG org.apache.camel.util.FileUtil - Tried 1 to delete file: /tmp/cachedir/cos7138988885969104934.tmp with result: true
16:15:23.505 [qtp422330142-21 - /myservice/v1/oper] DEBUG org.apache.camel.util.FileUtil - Retrying attempt 0 to delete file: /tmp/cachedir/cos8802932624903146810.tmp
16:15:23.505 [qtp422330142-21 - /myservice/v1/oper] DEBUG org.apache.camel.util.FileUtil - Tried 1 to delete file: /tmp/cachedir/cos8802932624903146810.tmp with result: true
16:15:23.505 [qtp422330142-21 - /myservice/v1/oper] DEBUG org.apache.camel.util.FileUtil - Retrying attempt 0 to delete file: /tmp/cachedir/cos91165405800652292.tmp
16:15:23.505 [qtp422330142-21 - /myservice/v1/oper] DEBUG org.apache.camel.util.FileUtil - Tried 1 to delete file: /tmp/cachedir/cos91165405800652292.tmp with result: true
16:15:23.506 [qtp422330142-21 - /myservice/v1/oper] DEBUG org.apache.camel.util.FileUtil - Retrying attempt 0 to delete file: /tmp/cachedir/cos6540772182497948066.tmp
16:15:23.506 [qtp422330142-21 - /myservice/v1/oper] DEBUG org.apache.camel.util.FileUtil - Tried 1 to delete file: /tmp/cachedir/cos6540772182497948066.tmp with result: true
16:15:23.506 [qtp422330142-21 - /myservice/v1/oper] DEBUG org.eclipse.jetty.server.Server - RESPONSE /myservice/v1/oper 201
所以它似乎起作用了。但我使用这个机制来保护自己不受OutOfMemory异常的影响。所以我写了Junit发送bigField,创建如下:
headers.setAll(map);
char[] chars = new char[20000000];
Arrays.fill(chars, 'a');
String bigField = new String(chars);
我用JAVA_OPTS=“-Xms60m-Xmx128m”
我错过了什么?我原以为这个流缓存机制可以保护我不受客户端发送大于Xmx-128MB的事件的影响,但它在20MB时失败
@SpringBootApplication
public class Application extends RouteBuilder {
@Override
public void configure() throws Exception {
setupStreamCaching();
restConfiguration().host("0.0.0.0").port(PORT)
.endpointProperty("headerFilterStrategy", "#myHeaderFilterStrategy")
.endpointProperty("matchOnUriPrefix", "true")
.endpointProperty("sendServerVersion", "false")
.bindingMode(RestBindingMode.json);
rest(API_CONTEXT + V1)
.post(API_OPERATION)
.type(RequestModel.class)
.outType(Response.class)
.consumes(APPLICATION_JSON)
.produces(APPLICATION_JSON)
.to(MAIN_ROUTE);
from(MAIN_ROUTE)
.routeId(MAIN_ROUTE)
.process(requestValidator)
.to(SERVICE_CALL)
.end();
private void setupStreamCaching() {
getContext().getStreamCachingStrategy().setSpoolDirectory("/tmp/cachedir");
getContext().getStreamCachingStrategy().setSpoolThreshold(64 * 1024);
getContext().getStreamCachingStrategy().setBufferSize(16 * 1024);
}
3:30:24.584[qtp1492219097-24-/myservice/v1/oper]调试
org.eclipse.jetty.io.ChannelEndPoint-填充3432
SelectChannelEndPoint@44b2fa12{/10.0.2.2:571251080,打开,输入,输出,-,0/30000,HttpConnection}{io=0,kio=0,kro=1}
13:30:24.585[qtp1492219097-24-/myservice/v1/oper]调试
o、 e.jetty.server.HttpConnection-
HttpConnection@13dbbbcc[重新填充,SelectChannelEndPoint@44b2fa12{/10.0.2.2:571251080,Open,in,out,-,0/30000,HttpConnection}{io=0,kio=0,kro=1}][p=HttpParser{s=CONTENT,19996672
属于
20000104},g=HttpGenerator{s=START},c=HttpChannelOverHttp@4b6953ae{r=1,c=false,a=DISPATCHED,uri=/myservice/v1/oper}]
已填充3432 13:30:24.585[qtp1492219097-24-/myservice/v1/oper]调试
org.eclipse.jetty.http.HttpParser-parseNext=CONTENT
HeapByteBuffer@42f6e192[p=0,l=3432,c=8192,r=3432]={aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
13:30:24.585[qtp1492219097-24-/myservice/v1/oper]调试
org.eclipse.jetty.server.HttpChannel-
HttpChannelOverHttp@4b6953ae{r=1,c=false,a=DISPATCHED,uri=/myservice/v1/oper}
content java.nio.HeapByteBufferR[pos=0 lim=3432 cap=8192]13:30:24.585
[qtp1492219097-24-/myservice/v1/oper]调试
org.eclipse.jetty.http.HttpParser-parseNext=CONTENT
HeapByteBuffer@42f6e192[p=3432,l=3432,c=8192,r=0]={aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
13:30:24.585[qtp1492219097-24-/myservice/v1/oper]调试
org.eclipse.jetty.http.HttpParser-内容-->结束13:30:24.585
[qtp1492219097-24-/myservice/v1/oper]调试
org.eclipse.jetty.server.HttpChannel-
HttpChannelOverHttp@4b6953ae{r=1,c=false,a=DISPATCHED,uri=/myservice/v1/oper}
messageComplete 13:30:24.585[qtp1492219097-24-/myservice/v1/oper]
调试org.eclipse.jetty.server.HttpInput-HttpInputOverHTTP@63602aee
EOF 13:30:24.585[qtp1492219097-24-/myservice/v1/oper]调试
org.eclipse.jetty.io.ChannelEndPoint-填充0
SelectChannelEndPoint@44b2fa12{/10.0.2.2:571251080,打开,输入,输出,-,1/30000,HttpConnection}{io=0,kio=0,kro=1}
13:30:24.586[qtp1492219097-24-/myservice/v1/oper]调试
o、 e.jetty.server.HttpConnection-
HttpConnection@13dbbbcc[重新填充,SelectChannelEndPoint@44b2fa12{/10.0.2.2:571251080,Open,in,out,-,2/30000,HttpConnection}{io=0,kio=0,kro=1}][p=HttpParser{s=END,20000104
属于
20000104},g=HttpGenerator{s=START},c=HttpChannelOverHttp@4b6953ae{r=1,c=false,a=DISPATCHED,uri=/myservice/v1/oper}]
已填充0 13:30:24.586[qtp1492219097-24-/myservice/v1/oper]调试
org.eclipse.jetty.server.HttpInput-HttpInputOverHTTP@63602aeeeof
EOF 13:30:24.586[qtp1492219097-24-/myservice/v1/oper]调试
org.eclipse.jetty.server.HttpInput-HttpInputOverHTTP@63602aeeeof
EOF 13:30:27.462[qtp1492219097-24-/myservice/v1/oper]警告
o、 e.jetty.servlet.ServletHandler-/myservice/v1/oper
org.apache.camel.TypeConversionException:类型转换期间出错
从类型:java.lang.String到所需类型:java.lang.String
值为[Body是org.apache.camel.StreamCache的实例]到期
java.lang.OutOfMemoryError:java堆空间
java.lang.OutOfMemoryError:位于的java堆空间
org.apache.camel.impl.converter.BaseTypeConverterRegistry.createTypeConversionException(BaseTypeConverterRegistry.java:629)
在
org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:150)
在
org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:78)
在
org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:53)
在
org.apache.camel.util.MessageHelper.extractBodyAsString(MessageHelper.java:84)
在
org.apache.camel.component.rest.RestConsumerBindingProcessor.process(RestConsumerBindingProcessor.java:162)
在
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
在
org.apache.camel.processor.RedeliveryRorHandler.process(RedeliveryRorHandler.java:542)
在
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
位于org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
org.apache.camel.processor.Pipeline.process(Pipeline.java:83)位于
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
在
org.apache.camel.component.jetty.CamelContinuationServlet.doService(CamelContinuationServlet.java:191)
在
org.apache.camel.http.common.CamelServlet.service(CamelServlet.java:74)
位于javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
在
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
在
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
在
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
在
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
在
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
在
org.e