mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Various fixes for the benchmark loader client. This can now do the job of loading, but still needs a few tweaks to dump summary reports.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6784 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -24,6 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.model.filefolder.loader;
|
package org.alfresco.repo.model.filefolder.loader;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@@ -43,6 +46,7 @@ public abstract class AbstractLoaderThread extends Thread
|
|||||||
protected final int testLoadDepth;
|
protected final int testLoadDepth;
|
||||||
|
|
||||||
private AtomicBoolean mustStop;
|
private AtomicBoolean mustStop;
|
||||||
|
Random random;
|
||||||
|
|
||||||
public AbstractLoaderThread(
|
public AbstractLoaderThread(
|
||||||
LoaderSession session,
|
LoaderSession session,
|
||||||
@@ -60,6 +64,7 @@ public abstract class AbstractLoaderThread extends Thread
|
|||||||
this.testLoadDepth = testLoadDepth;
|
this.testLoadDepth = testLoadDepth;
|
||||||
|
|
||||||
this.mustStop = new AtomicBoolean(false);
|
this.mustStop = new AtomicBoolean(false);
|
||||||
|
this.random = new Random();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,8 +80,6 @@ public abstract class AbstractLoaderThread extends Thread
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
|
||||||
|
|
||||||
int testCount = 0;
|
int testCount = 0;
|
||||||
while (!mustStop.get())
|
while (!mustStop.get())
|
||||||
{
|
{
|
||||||
@@ -93,9 +96,11 @@ public abstract class AbstractLoaderThread extends Thread
|
|||||||
NodeRef workingRootNodeRef = session.getWorkingRootNodeRefs().get(nodeIndex);
|
NodeRef workingRootNodeRef = session.getWorkingRootNodeRefs().get(nodeIndex);
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
doLoading(serverProxy, workingRootNodeRef);
|
String msg = doLoading(serverProxy, workingRootNodeRef);
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
// Dump the specifics of the load
|
||||||
|
|
||||||
// Have we done this enough?
|
// Have we done this enough?
|
||||||
testCount++;
|
testCount++;
|
||||||
if (testCount > testTotal)
|
if (testCount > testTotal)
|
||||||
@@ -121,12 +126,45 @@ public abstract class AbstractLoaderThread extends Thread
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void dumpLoadSpecifics(long startTime, long endTime, String msg)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param serverProxy the server to load
|
* @param serverProxy the server to load
|
||||||
* @param workingRootNodeRef the root of the hierarchy to use
|
* @param workingRootNodeRef the root of the hierarchy to use
|
||||||
|
* @return a brief description of the loading
|
||||||
* @throws Exception any exception will be handled
|
* @throws Exception any exception will be handled
|
||||||
*/
|
*/
|
||||||
protected abstract void doLoading(
|
protected abstract String doLoading(
|
||||||
LoaderServerProxy serverProxy,
|
LoaderServerProxy serverProxy,
|
||||||
NodeRef workingRootNodeRef) throws Exception;
|
NodeRef workingRootNodeRef) throws Exception;
|
||||||
|
|
||||||
|
protected List<String> chooseFolderPath()
|
||||||
|
{
|
||||||
|
int[] folderProfiles = session.getFolderProfiles();
|
||||||
|
// We work through these until we get the required depth.
|
||||||
|
// The root node is ignored as it acts as the search root
|
||||||
|
List<String> path = new ArrayList<String>(testLoadDepth);
|
||||||
|
for (int i = 1; i < folderProfiles.length; i++)
|
||||||
|
{
|
||||||
|
int folderProfile = folderProfiles[i];
|
||||||
|
int randomFolderId = random.nextInt(folderProfile);
|
||||||
|
String name = String.format("folder-%05d", randomFolderId);
|
||||||
|
path.add(name);
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected File getFile() throws Exception
|
||||||
|
{
|
||||||
|
File[] files = session.getSourceFiles();
|
||||||
|
File file = files[random.nextInt(files.length)];
|
||||||
|
if (!file.exists() || file.isDirectory())
|
||||||
|
{
|
||||||
|
throw new LoaderClientException("Cannot find loading file: " + file);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -109,7 +109,7 @@ public class FileFolderRemoteLoader
|
|||||||
for (AbstractLoaderThread thread : threads)
|
for (AbstractLoaderThread thread : threads)
|
||||||
{
|
{
|
||||||
String summary = thread.getSummary();
|
String summary = thread.getSummary();
|
||||||
session.logNormal(summary);
|
session.logSummary(summary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,6 +178,13 @@ public class FileFolderRemoteLoader
|
|||||||
{
|
{
|
||||||
folderProfiles[i] = folderProfilesList.get(i);
|
folderProfiles[i] = folderProfilesList.get(i);
|
||||||
}
|
}
|
||||||
|
if (folderProfiles.length == 0 || folderProfiles[0] != 1)
|
||||||
|
{
|
||||||
|
throw new LoaderClientException(
|
||||||
|
"'" + PROP_SESSION_FOLDER_PROFILE + "' must always start with '1', " +
|
||||||
|
"which represents the root of the hierarchy, and have at least one other value. " +
|
||||||
|
"E.g. '1, 3'");
|
||||||
|
}
|
||||||
|
|
||||||
// Construct
|
// Construct
|
||||||
LoaderSession session = new LoaderSession(
|
LoaderSession session = new LoaderSession(
|
||||||
@@ -313,14 +320,29 @@ public class FileFolderRemoteLoader
|
|||||||
// Run
|
// Run
|
||||||
app.start();
|
app.start();
|
||||||
|
|
||||||
synchronized(app)
|
// Now lower this threads priority
|
||||||
{
|
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
|
||||||
app.wait(1000L);
|
|
||||||
}
|
|
||||||
// System.out.println(""
|
|
||||||
|
|
||||||
|
// Wait for a quit signal
|
||||||
|
System.out.println("Running test " + app.session.getName() + ". Enter 'q' to quit");
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
int keyPress = System.in.read();
|
||||||
|
if (keyPress == 'Q' || keyPress == 'q')
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (System.in.available() > 0)
|
||||||
|
{
|
||||||
|
// Don't wait, just process
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// No more keypresses so just wait
|
||||||
|
Thread.yield();
|
||||||
|
}
|
||||||
// Finish off
|
// Finish off
|
||||||
app.stop();
|
app.stop();
|
||||||
|
System.out.println("The test is complete.");
|
||||||
}
|
}
|
||||||
catch (LoaderClientException e)
|
catch (LoaderClientException e)
|
||||||
{
|
{
|
||||||
|
@@ -27,6 +27,7 @@ package org.alfresco.repo.model.filefolder.loader;
|
|||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -64,8 +65,9 @@ public class LoaderSession
|
|||||||
private List<LoaderServerProxy> remoteServers;
|
private List<LoaderServerProxy> remoteServers;
|
||||||
private List<NodeRef> workingRootNodeRefs;
|
private List<NodeRef> workingRootNodeRefs;
|
||||||
private File[] sourceFiles;
|
private File[] sourceFiles;
|
||||||
private OutputStream outStream;
|
private OutputStream outVerbose;
|
||||||
private OutputStream errStream;
|
private OutputStream outSummary;
|
||||||
|
private OutputStream outError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -153,19 +155,23 @@ public class LoaderSession
|
|||||||
|
|
||||||
// Construct output and error files
|
// Construct output and error files
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
File outFile = new File("./LoaderSession-" + name + "-"+ time + "-out.txt");
|
File fileVerbose = new File("./LoaderSession-" + name + "-"+ time + "-verbose.txt");
|
||||||
File errFile = new File("./LoaderSession-" + name + "-"+ time + "-err.txt");
|
File fileSummary = new File("./LoaderSession-" + name + "-"+ time + "-summary.txt");
|
||||||
outStream = new BufferedOutputStream(new FileOutputStream(outFile));
|
File fileError = new File("./LoaderSession-" + name + "-"+ time + "-error.txt");
|
||||||
errStream = new BufferedOutputStream(new FileOutputStream(errFile));
|
outVerbose = new BufferedOutputStream(new FileOutputStream(fileVerbose));
|
||||||
|
outSummary = new BufferedOutputStream(new FileOutputStream(fileSummary));
|
||||||
|
outError = new BufferedOutputStream(new FileOutputStream(fileError));
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void close()
|
public synchronized void close()
|
||||||
{
|
{
|
||||||
try { outStream.close(); } catch (Throwable e) {}
|
try { outVerbose.close(); } catch (Throwable e) {}
|
||||||
try { errStream.close(); } catch (Throwable e) {}
|
try { outSummary.close(); } catch (Throwable e) {}
|
||||||
|
try { outError.close(); } catch (Throwable e) {}
|
||||||
|
|
||||||
outStream = null;
|
outVerbose = null;
|
||||||
errStream = null;
|
outSummary = null;
|
||||||
|
outError = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -337,50 +343,75 @@ public class LoaderSession
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logVerbose(String msg)
|
private void writeLineEnding(OutputStream out) throws IOException
|
||||||
{
|
{
|
||||||
if (!verbose)
|
if (File.separatorChar == '/')
|
||||||
{
|
{
|
||||||
// Just ignore it
|
// It's unix
|
||||||
|
out.write('\n');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Windows
|
||||||
|
out.write('\r');
|
||||||
|
out.write('\n');
|
||||||
}
|
}
|
||||||
logNormal(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void logNormal(String msg)
|
public synchronized void logVerbose(String msg)
|
||||||
{
|
{
|
||||||
if (outStream == null)
|
if (!verbose || outVerbose == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
byte[] bytes = msg.getBytes("UTF-8");
|
byte[] bytes = msg.getBytes("UTF-8");
|
||||||
outStream.write(bytes);
|
outVerbose.write(bytes);
|
||||||
outStream.write('\n');
|
writeLineEnding(outVerbose);
|
||||||
outStream.flush();
|
outVerbose.flush();
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
System.err.println("Failed to write message to output file: " + e.getMessage());
|
System.err.println("Failed to write message to verbose file: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void logSummary(String msg)
|
||||||
|
{
|
||||||
|
if (outSummary == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] bytes = msg.getBytes("UTF-8");
|
||||||
|
outSummary.write(bytes);
|
||||||
|
writeLineEnding(outSummary);
|
||||||
|
outSummary.flush();
|
||||||
|
}
|
||||||
|
catch (Throwable e)
|
||||||
|
{
|
||||||
|
System.err.println("Failed to write message to summary file: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void logError(String msg)
|
public synchronized void logError(String msg)
|
||||||
{
|
{
|
||||||
if (errStream == null)
|
if (outSummary == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
byte[] bytes = msg.getBytes("UTF-8");
|
byte[] bytes = msg.getBytes("UTF-8");
|
||||||
errStream.write(bytes);
|
outSummary.write(bytes);
|
||||||
outStream.write('\n');
|
writeLineEnding(outError);
|
||||||
errStream.flush();
|
outSummary.flush();
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
System.err.println("Failed to write message to output file: " + e.getMessage());
|
System.err.println("Failed to write message to error file: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.model.filefolder.loader;
|
package org.alfresco.repo.model.filefolder.loader;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.service.cmr.model.FileInfo;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.util.GUID;
|
||||||
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A description of what the remote loader should do.
|
* A description of what the remote loader should do.
|
||||||
@@ -44,14 +51,52 @@ public class LoaderUploadThread extends AbstractLoaderThread
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doLoading(LoaderServerProxy serverProxy, NodeRef workingRootNodeRef) throws Exception
|
protected String doLoading(LoaderServerProxy serverProxy, NodeRef workingRootNodeRef) throws Exception
|
||||||
{
|
{
|
||||||
int totalNodeCount = serverProxy.loaderRemote.getNodeCount(
|
// Get a random folder
|
||||||
serverProxy.ticket);
|
List<String> folderPath = super.chooseFolderPath();
|
||||||
int storeNodeCount = serverProxy.loaderRemote.getNodeCount(
|
// Make sure the folder exists
|
||||||
|
FileInfo folderInfo = serverProxy.fileFolderRemote.makeFolders(
|
||||||
serverProxy.ticket,
|
serverProxy.ticket,
|
||||||
workingRootNodeRef.getStoreRef());
|
workingRootNodeRef,
|
||||||
session.logVerbose("Nodes: " + totalNodeCount + ". Store Nodes: " + storeNodeCount);
|
folderPath,
|
||||||
|
ContentModel.TYPE_FOLDER);
|
||||||
|
|
||||||
|
// Get a random file
|
||||||
|
File file = getFile();
|
||||||
|
byte[] bytes = FileCopyUtils.copyToByteArray(file);
|
||||||
|
// Get the extension
|
||||||
|
String filename = GUID.generate();
|
||||||
|
int index = file.getName().lastIndexOf('.');
|
||||||
|
if (index > 0)
|
||||||
|
{
|
||||||
|
String ext = file.getName().substring(index + 1, file.getName().length());
|
||||||
|
filename += ("." + ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upload it
|
||||||
|
NodeRef folderNodeRef = folderInfo.getNodeRef();
|
||||||
|
|
||||||
|
FileInfo fileInfo = serverProxy.fileFolderRemote.create(
|
||||||
|
serverProxy.ticket,
|
||||||
|
folderNodeRef,
|
||||||
|
filename,
|
||||||
|
ContentModel.TYPE_CONTENT);
|
||||||
|
NodeRef fileNodeRef = fileInfo.getNodeRef();
|
||||||
|
serverProxy.fileFolderRemote.putContent(serverProxy.ticket, fileNodeRef, bytes, filename);
|
||||||
|
|
||||||
|
// Done
|
||||||
|
String msg = String.format("Uploaded %s to folder: %s", filename, folderPath.toString());
|
||||||
|
session.logVerbose(msg);
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
|
||||||
|
// int totalNodeCount = serverProxy.loaderRemote.getNodeCount(
|
||||||
|
// serverProxy.ticket);
|
||||||
|
// int storeNodeCount = serverProxy.loaderRemote.getNodeCount(
|
||||||
|
// serverProxy.ticket,
|
||||||
|
// workingRootNodeRef.getStoreRef());
|
||||||
|
// session.logVerbose("Nodes: " + totalNodeCount + ". Store Nodes: " + storeNodeCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user