Author: mgrigorov
Date: Thu Jun 23 08:19:28 2011
New Revision: 1138761

URL: http://svn.apache.org/viewvc?rev=1138761&view=rev
Log:
WICKET-3788 wicket FileChannelPool has scalability issues

Remove FileChannelPool because it doesn't give performance improvements.


Modified:
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/DefaultPageManagerProvider.java
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/pageStore/DiskDataStore.java
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/IStoreSettings.java
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/def/StoreSettings.java
    
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/page/persistent/disk/DiskDataStoreTest.java
    
wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/StoreSettings.java
    
wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/StoreSettingsMBean.java

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/DefaultPageManagerProvider.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/DefaultPageManagerProvider.java?rev=1138761&r1=1138760&r2=1138761&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/DefaultPageManagerProvider.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/DefaultPageManagerProvider.java
 Thu Jun 23 08:19:28 2011
@@ -66,11 +66,9 @@ public class DefaultPageManagerProvider 
        {
                IStoreSettings storeSettings = getStoreSettings();
                Bytes maxSizePerSession = storeSettings.getMaxSizePerSession();
-               int fileChannelPoolCapacity = 
storeSettings.getFileChannelPoolCapacity();
                File fileStoreFolder = storeSettings.getFileStoreFolder();
 
-               return new DiskDataStore(application.getName(), 
fileStoreFolder, maxSizePerSession,
-                       fileChannelPoolCapacity);
+               return new DiskDataStore(application.getName(), 
fileStoreFolder, maxSizePerSession);
        }
 
        IStoreSettings getStoreSettings()

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/pageStore/DiskDataStore.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/pageStore/DiskDataStore.java?rev=1138761&r1=1138760&r2=1138761&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/pageStore/DiskDataStore.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/pageStore/DiskDataStore.java
 Thu Jun 23 08:19:28 2011
@@ -18,12 +18,14 @@ package org.apache.wicket.pageStore;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.OutputStream;
+import java.io.RandomAccessFile;
 import java.io.Serializable;
 import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
@@ -36,6 +38,7 @@ import java.util.concurrent.ConcurrentMa
 import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.pageStore.PageWindowManager.PageWindow;
 import org.apache.wicket.util.file.Files;
+import org.apache.wicket.util.io.IOUtils;
 import org.apache.wicket.util.lang.Args;
 import org.apache.wicket.util.lang.Bytes;
 import org.slf4j.Logger;
@@ -54,8 +57,6 @@ public class DiskDataStore implements ID
 
        private final Bytes maxSizePerPageSession;
 
-       private final FileChannelPool fileChannelPool;
-
        private final File fileStoreFolder;
 
        private final ConcurrentMap<String, SessionEntry> sessionEntryMap;
@@ -69,7 +70,7 @@ public class DiskDataStore implements ID
         * @param fileChannelPoolCapacity
         */
        public DiskDataStore(final String applicationName, final File 
fileStoreFolder,
-               final Bytes maxSizePerSession, final int 
fileChannelPoolCapacity)
+               final Bytes maxSizePerSession)
        {
                this.applicationName = applicationName;
                this.fileStoreFolder = fileStoreFolder;
@@ -78,8 +79,6 @@ public class DiskDataStore implements ID
 
                try
                {
-                       fileChannelPool = new 
FileChannelPool(fileChannelPoolCapacity);
-
                        this.fileStoreFolder.mkdirs();
                        loadIndex();
                }
@@ -99,7 +98,6 @@ public class DiskDataStore implements ID
        {
                log.debug("Destroying...");
                saveIndex();
-               fileChannelPool.destroy();
                log.debug("Destroyed.");
        }
 
@@ -321,9 +319,7 @@ public class DiskDataStore implements ID
                                // allocate window for page
                                PageWindow window = 
getManager().createPageWindow(pageId, data.length);
 
-                               // take the filechannel from the pool
-                               FileChannel channel = 
diskDataStore.fileChannelPool.getFileChannel(getFileName(),
-                                       true);
+                               FileChannel channel = getFileChannel(true);
                                try
                                {
                                        // write the content
@@ -335,8 +331,7 @@ public class DiskDataStore implements ID
                                }
                                finally
                                {
-                                       // return the "borrowed" file channel
-                                       
diskDataStore.fileChannelPool.returnFileChannel(channel);
+                                       IOUtils.closeQuietly(channel);
                                }
                        }
                }
@@ -364,7 +359,7 @@ public class DiskDataStore implements ID
                public byte[] loadPage(PageWindow window)
                {
                        byte[] result = null;
-                       FileChannel channel = 
diskDataStore.fileChannelPool.getFileChannel(getFileName(), false);
+                       FileChannel channel = getFileChannel(false);
                        if (channel != null)
                        {
                                ByteBuffer buffer = 
ByteBuffer.allocate(window.getFilePartSize());
@@ -382,12 +377,33 @@ public class DiskDataStore implements ID
                                }
                                finally
                                {
-                                       
diskDataStore.fileChannelPool.returnFileChannel(channel);
+                                       IOUtils.closeQuietly(channel);
                                }
                        }
                        return result;
                }
 
+               private FileChannel getFileChannel(boolean create)
+               {
+                       FileChannel channel = null;
+                       File file = new File(getFileName());
+                       if (create || file.exists())
+                       {
+                               String mode = create ? "rw" : "r";
+                               try
+                               {
+                                       RandomAccessFile randomAccessFile = new 
RandomAccessFile(file, mode);
+                                       channel = randomAccessFile.getChannel();
+                               }
+                               catch (FileNotFoundException fnfx)
+                               {
+                                       // should not happen. we check 
explicitly earlier
+                                       log.error(fnfx.getMessage(), fnfx);
+                               }
+                       }
+                       return channel;
+               }
+
                /**
                 * Loads the specified page data.
                 * 
@@ -414,7 +430,6 @@ public class DiskDataStore implements ID
                 */
                public synchronized void unbind()
                {
-                       
diskDataStore.fileChannelPool.closeAndDeleteFileChannel(getFileName());
                        File sessionFolder = 
diskDataStore.getSessionFolder(sessionId, false);
                        if (sessionFolder.exists())
                        {

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/IStoreSettings.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/IStoreSettings.java?rev=1138761&r1=1138760&r2=1138761&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/IStoreSettings.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/IStoreSettings.java
 Thu Jun 23 08:19:28 2011
@@ -33,20 +33,6 @@ import org.apache.wicket.util.lang.Bytes
  */
 public interface IStoreSettings
 {
-
-       /**
-        * @return the maximum number of opened file channels by {@link 
DiskDataStore}.
-        */
-       int getFileChannelPoolCapacity();
-
-       /**
-        * Sets the number of maximum opened file channels by {@link 
DiskDataStore}
-        * 
-        * @param capacity
-        *            the new maximum number of opened file channels
-        */
-       void setFileChannelPoolCapacity(int capacity);
-
        /**
         * @return the number of page instances which will be stored in the 
http session for faster
         *         retrieval

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/def/StoreSettings.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/def/StoreSettings.java?rev=1138761&r1=1138760&r2=1138761&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/def/StoreSettings.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/def/StoreSettings.java
 Thu Jun 23 08:19:28 2011
@@ -33,14 +33,10 @@ public class StoreSettings implements IS
 {
        private static final int DEFAULT_CACHE_SIZE = 40;
 
-       private static final int DEFAULT_FILE_CHANNEL_POOL_CAPACITY = 50;
-
        private static final Bytes DEFAULT_MAX_SIZE_PER_SESSION = 
Bytes.megabytes(10);
 
        private static final int DEFAULT_ASYNCHRONOUS_QUEUE_CAPACITY = 100;
 
-       private int fileChannelPoolCapacity = 
DEFAULT_FILE_CHANNEL_POOL_CAPACITY;
-
        private int inmemoryCacheSize = DEFAULT_CACHE_SIZE;
 
        private Bytes maxSizePerSession = DEFAULT_MAX_SIZE_PER_SESSION;
@@ -58,21 +54,6 @@ public class StoreSettings implements IS
        {
        }
 
-       public int getFileChannelPoolCapacity()
-       {
-               return fileChannelPoolCapacity;
-       }
-
-       public void setFileChannelPoolCapacity(int capacity)
-       {
-               if (capacity < 0)
-               {
-                       throw new IllegalArgumentException(
-                               "File channel pool capacity must be a positive 
number.");
-               }
-               fileChannelPoolCapacity = capacity;
-       }
-
        public int getInmemoryCacheSize()
        {
                return inmemoryCacheSize;

Modified: 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/page/persistent/disk/DiskDataStoreTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/page/persistent/disk/DiskDataStoreTest.java?rev=1138761&r1=1138760&r2=1138761&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/page/persistent/disk/DiskDataStoreTest.java
 (original)
+++ 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/page/persistent/disk/DiskDataStoreTest.java
 Thu Jun 23 08:19:28 2011
@@ -337,8 +337,7 @@ public class DiskDataStoreTest extends T
                IStoreSettings storeSettings = new StoreSettings(null);
                java.io.File fileStoreFolder = 
storeSettings.getFileStoreFolder();
 
-               dataStore = new DiskDataStore("app1", fileStoreFolder, 
MAX_SIZE_PER_SESSION,
-                       FILE_CHANNEL_POOL_CAPACITY);
+               dataStore = new DiskDataStore("app1", fileStoreFolder, 
MAX_SIZE_PER_SESSION);
                int asynchronousQueueCapacity = 
storeSettings.getAsynchronousQueueCapacity();
                dataStore = new AsynchronousDataStore(dataStore, 
asynchronousQueueCapacity);
 

Modified: 
wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/StoreSettings.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/StoreSettings.java?rev=1138761&r1=1138760&r2=1138761&view=diff
==============================================================================
--- 
wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/StoreSettings.java 
(original)
+++ 
wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/StoreSettings.java 
Thu Jun 23 08:19:28 2011
@@ -35,11 +35,6 @@ public class StoreSettings implements St
                this.application = application;
        }
 
-       public int getFileChannelPoolCapacity()
-       {
-               return 
application.getStoreSettings().getFileChannelPoolCapacity();
-       }
-
        public int getInmemoryCacheSize()
        {
                return application.getStoreSettings().getInmemoryCacheSize();

Modified: 
wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/StoreSettingsMBean.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/StoreSettingsMBean.java?rev=1138761&r1=1138760&r2=1138761&view=diff
==============================================================================
--- 
wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/StoreSettingsMBean.java
 (original)
+++ 
wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/StoreSettingsMBean.java
 Thu Jun 23 08:19:28 2011
@@ -25,11 +25,6 @@ public interface StoreSettingsMBean
 {
 
        /**
-        * @return the maximum number of opened file channels by {@link 
DiskDataStore}.
-        */
-       int getFileChannelPoolCapacity();
-
-       /**
         * @return the number of page instances which will be stored in the 
http session for faster
         *         retrieval
         */


Reply via email to