Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5132C18C09 for ; Tue, 8 Mar 2016 22:02:14 +0000 (UTC) Received: (qmail 42496 invoked by uid 500); 8 Mar 2016 22:02:14 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 42432 invoked by uid 500); 8 Mar 2016 22:02:14 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 42423 invoked by uid 99); 8 Mar 2016 22:02:14 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Mar 2016 22:02:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1A728DFBAD; Tue, 8 Mar 2016 22:02:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: cschneider@apache.org To: commits@cxf.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: cxf-dosgi git commit: [DOSGI-230] Make threads configurable, add logging Date: Tue, 8 Mar 2016 22:02:14 +0000 (UTC) Repository: cxf-dosgi Updated Branches: refs/heads/master 735c6c7c5 -> 221f4ba7f [DOSGI-230] Make threads configurable, add logging Project: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/commit/221f4ba7 Tree: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/tree/221f4ba7 Diff: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/diff/221f4ba7 Branch: refs/heads/master Commit: 221f4ba7f43c706169ce0f528ebc717f1dd47620 Parents: 735c6c7 Author: Christian Schneider Authored: Tue Mar 8 23:02:07 2016 +0100 Committer: Christian Schneider Committed: Tue Mar 8 23:02:07 2016 +0100 ---------------------------------------------------------------------- .../org/apache/aries/rsa/provider/tcp/TCPServer.java | 15 +++++++-------- .../apache/aries/rsa/provider/tcp/TcpEndpoint.java | 9 +++++---- .../aries/rsa/provider/tcp/TcpProviderTest.java | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/221f4ba7/dsw/cxf-dosgi-tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TCPServer.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dosgi-tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TCPServer.java b/dsw/cxf-dosgi-tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TCPServer.java index dd8e423..e70731d 100644 --- a/dsw/cxf-dosgi-tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TCPServer.java +++ b/dsw/cxf-dosgi-tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TCPServer.java @@ -19,7 +19,6 @@ package org.apache.aries.rsa.provider.tcp; import java.io.Closeable; -import java.io.EOFException; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -34,13 +33,17 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class TCPServer implements Closeable, Runnable { + private Logger log = LoggerFactory.getLogger(TCPServer.class); private ServerSocket serverSocket; private Object service; private boolean running; private ExecutorService executor; - public TCPServer(Object service, String localip, Integer port) { + public TCPServer(Object service, String localip, Integer port, int numThreads) { this.service = service; try { this.serverSocket = new ServerSocket(port); @@ -49,7 +52,7 @@ public class TCPServer implements Closeable, Runnable { } this.running = true; this.executor = Executors.newCachedThreadPool(); - for (int c = 0; c < 100; c++) { + for (int c = 0; c < numThreads; c++) { this.executor.execute(this); } } @@ -57,8 +60,6 @@ public class TCPServer implements Closeable, Runnable { int getPort() { return this.serverSocket.getLocalPort(); } - - public void run() { ClassLoader serviceCL = service.getClass().getClassLoader(); @@ -74,10 +75,8 @@ public class TCPServer implements Closeable, Runnable { objectOutput.writeObject(result); } catch (SocketException e) { running = false; - } catch (EOFException e) { - // This is normal } catch (Exception e) { - e.printStackTrace(); + log.warn("Error processing service call.", e); } } } http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/221f4ba7/dsw/cxf-dosgi-tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpEndpoint.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dosgi-tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpEndpoint.java b/dsw/cxf-dosgi-tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpEndpoint.java index b45347a..5bc9d7a 100644 --- a/dsw/cxf-dosgi-tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpEndpoint.java +++ b/dsw/cxf-dosgi-tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpEndpoint.java @@ -30,18 +30,19 @@ public class TcpEndpoint implements Endpoint { private TCPServer tcpServer; public TcpEndpoint(Object service, Map effectiveProperties) { - Integer port = getInt(effectiveProperties, "port"); + Integer port = getInt(effectiveProperties, "port", 0); String localip = LocalHostUtil.getLocalIp(); - tcpServer = new TCPServer(service, localip, port); + int numThreads = getInt(effectiveProperties, "numThreads", 10); + tcpServer = new TCPServer(service, localip, port, numThreads); effectiveProperties.put(RemoteConstants.ENDPOINT_ID, "tcp://" + localip + ":" + tcpServer.getPort()); effectiveProperties.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, ""); this.epd = new EndpointDescription(effectiveProperties); } - private Integer getInt(Map effectiveProperties, String key) { + private Integer getInt(Map effectiveProperties, String key, int defaultValue) { String value = (String)effectiveProperties.get(key); - return value != null ? Integer.parseInt(value) : 0; + return value != null ? Integer.parseInt(value) : defaultValue; } @Override http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/221f4ba7/dsw/cxf-dosgi-tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dosgi-tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderTest.java b/dsw/cxf-dosgi-tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderTest.java index 570bc85..ec59456 100644 --- a/dsw/cxf-dosgi-tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderTest.java +++ b/dsw/cxf-dosgi-tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderTest.java @@ -36,7 +36,7 @@ import org.osgi.framework.Constants; public class TcpProviderTest { - private static final int NUM_CALLS = 10000; + private static final int NUM_CALLS = 100; private MyService myServiceProxy; private Endpoint ep; @@ -54,7 +54,7 @@ public class TcpProviderTest { @Test public void testPerf() throws IOException, InterruptedException { - //runPerfTest(myServiceProxy); + runPerfTest(myServiceProxy); String msg = "test"; String result = myServiceProxy.echo(msg); Assert.assertEquals(msg, result); @@ -81,7 +81,7 @@ public class TcpProviderTest { msg.append("testing123"); } final String msg2 = msg.toString(); - ExecutorService executor = Executors.newFixedThreadPool(100); + ExecutorService executor = Executors.newFixedThreadPool(10); Runnable task = new Runnable() { @Override @@ -97,6 +97,6 @@ public class TcpProviderTest { executor.shutdown(); executor.awaitTermination(100, TimeUnit.SECONDS); long tps = NUM_CALLS * 1000 / (System.currentTimeMillis() - start); - System.out.println(tps); + System.out.println(tps + " tps"); } }