summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-12-30 12:35:20 (EST)
committerEike Stepper2007-12-30 12:35:20 (EST)
commitc425fb554da58f0a616bf3ec488058863873a67a (patch)
tree0c5264f859d1d0654ec2af6b049dca02e9f6d09c
parent3bdf3aa9efb5f972ce3b80e5ea6a50bfb3bbec55 (diff)
downloadcdo-c425fb554da58f0a616bf3ec488058863873a67a.zip
cdo-c425fb554da58f0a616bf3ec488058863873a67a.tar.gz
cdo-c425fb554da58f0a616bf3ec488058863873a67a.tar.bz2
[213748] Connection delays with Windows Vista
https://bugs.eclipse.org/bugs/show_bug.cgi?id=213748
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/CDO AllTests.launch2
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java54
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/Performance.java111
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SelectorTest.java2
4 files changed, 163 insertions, 6 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/CDO AllTests.launch b/plugins/org.eclipse.emf.cdo.tests/CDO AllTests.launch
index e28a40a..8c875b2 100644
--- a/plugins/org.eclipse.emf.cdo.tests/CDO AllTests.launch
+++ b/plugins/org.eclipse.emf.cdo.tests/CDO AllTests.launch
@@ -15,5 +15,5 @@
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.emf.cdo.tests.AllTests"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.emf.cdo.tests"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Ddebug=true"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Ddebug=true&#13;&#10;-Dvista.cache.selector"/>
</launchConfiguration>
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java
index a15f40d..467785b 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java
@@ -38,6 +38,10 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, TCPSelector.class);
+ private static final boolean VISTA = System.getProperty("vista.cache.selector") != null;
+
+ private static Selector vistaCache;
+
private Selector selector;
private transient Queue<Runnable> clientOperations = new ConcurrentLinkedQueue<Runnable>();
@@ -257,14 +261,56 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
}
}
+ protected Selector openSelector() throws IOException
+ {
+ if (VISTA)
+ {
+ if (vistaCache == null)
+ {
+ vistaCache = Selector.open();
+ }
+
+ return vistaCache;
+ }
+
+ return Selector.open();
+ }
+
+ protected void closeSelector() throws IOException
+ {
+ if (VISTA)
+ {
+ for (SelectionKey key : selector.keys())
+ {
+ try
+ {
+ key.cancel();
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ try
+ {
+ selector.selectNow();
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ else
+ {
+ selector.close();
+ }
+ }
+
@Override
protected void doActivate() throws Exception
{
super.doActivate();
running = true;
- long start = System.currentTimeMillis();
- selector = Selector.open();
- System.out.println("OPEN SELECTOR: " + (System.currentTimeMillis() - start));
+ selector = openSelector();
thread = new Thread(this, "TCPSelector"); //$NON-NLS-1$
thread.setDaemon(true);
@@ -296,7 +342,7 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
try
{
- selector.close();
+ closeSelector();
}
catch (Exception ex)
{
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/Performance.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/Performance.java
new file mode 100644
index 0000000..6dee94d
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/Performance.java
@@ -0,0 +1,111 @@
+package org.eclipse.net4j.tests;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.nio.channels.Selector;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @author Eike Stepper
+ */
+public class Performance
+{
+ public static void main(String[] args) throws Exception
+ {
+ testInetAddress();
+ testServerSocket();
+ testSocket();
+ testSelector();
+ }
+
+ public static void testInetAddress() throws Exception
+ {
+ System.out.println(InetAddress.class.getName());
+ for (int i = 0; i < 2; i++)
+ {
+ long start = System.currentTimeMillis();
+ InetAddress inet = InetAddress.getByName("localhost");
+ inet.getHostAddress();
+ long duration = System.currentTimeMillis() - start;
+
+ System.out.println(duration);
+ }
+ }
+
+ public static void testServerSocket() throws IOException
+ {
+ System.out.println(ServerSocket.class.getName());
+ for (int i = 0; i < 2; i++)
+ {
+ long start = System.currentTimeMillis();
+ ServerSocket serverSocket = new ServerSocket(2036);
+ long duration = System.currentTimeMillis() - start;
+
+ System.out.println(duration);
+ serverSocket.close();
+ }
+ }
+
+ public static void testSocket() throws Exception
+ {
+ System.out.println(Socket.class.getName());
+ for (int i = 0; i < 2; i++)
+ {
+ final CountDownLatch latch = new CountDownLatch(1);
+ new Thread()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ ServerSocket serverSocket = new ServerSocket(2036);
+ latch.countDown();
+
+ Socket socket = serverSocket.accept();
+ socket.close();
+ serverSocket.close();
+ }
+ catch (IOException ex)
+ {
+ ex.printStackTrace();
+ latch.countDown();
+ }
+ }
+ }.start();
+
+ latch.await();
+ Thread.sleep(500);
+
+ Socket socket = new Socket(Proxy.NO_PROXY);
+ SocketAddress endpoint = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 2036);
+
+ long start = System.currentTimeMillis();
+ socket.connect(endpoint);
+ long duration = System.currentTimeMillis() - start;
+
+ System.out.println(duration);
+ Thread.sleep(500);
+ }
+ }
+
+ public static void testSelector() throws IOException
+ {
+ SelectorProvider provider = SelectorProvider.provider();
+ System.out.println(provider.getClass().getName());
+ for (int i = 0; i < 2; i++)
+ {
+ long start = System.currentTimeMillis();
+ Selector selector = provider.openSelector();
+ long duration = System.currentTimeMillis() - start;
+
+ System.out.println(duration);
+ selector.close();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SelectorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SelectorTest.java
index 81a2688..21b6622 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SelectorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SelectorTest.java
@@ -24,7 +24,7 @@ public class SelectorTest extends TestCase
{
SelectorProvider provider = SelectorProvider.provider();
System.out.println(provider.getClass().getName());
- for (int i = 0; i < 10; i++)
+ for (int i = 0; i < 5; i++)
{
long start = System.currentTimeMillis();
Selector selector = provider.openSelector();