incubator-olio-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject svn commit: r745169 [1/3] - in /incubator/olio/workload/php/trunk/src: com/ org/ org/apache/ org/apache/olio/ org/apache/olio/workload/ org/apache/olio/workload/driver/ org/apache/olio/workload/fsloader/ org/apache/olio/workload/harness/ org/apache/oli...
Date Tue, 17 Feb 2009 17:43:26 GMT
Author: shanti
Date: Tue Feb 17 17:43:25 2009
New Revision: 745169

URL: http://svn.apache.org/viewvc?rev=745169&view=rev
Log:
Fix for OLIO-50 from Akara
Added object pooling and used it to throttle down data creation rates to match the 
insertion rate, leaving a buffer of readily loadable objects so the loader threads 
don't have to wait. Objects are returned to the pool after loading.
Pool prohibits object creation. So the loader API has to change to class based 
identification, i.e. load(Person.class, 500) will load 500 person objects. Moreover, 
the types have to be loaded in parallel as each type loading will stall the main 
thread from loading another type below. Iteration has been taken out of the 
LoadController and done in the loader using a different thread for each type. 
We also needed to change the Loadable spec to no-arg constructor (to be constructed 
by the pool and not by the user) and provide the sequence using the getSequence call into Loadable. 
Fix for OLIO-13 from Shanti
Re-factored all code to use org.apache.olio.workload as package name

Added:
    incubator/olio/workload/php/trunk/src/org/   (props changed)
      - copied from r741658, incubator/olio/workload/php/trunk/src/com/
    incubator/olio/workload/php/trunk/src/org/apache/   (props changed)
      - copied from r741658, incubator/olio/workload/php/trunk/src/com/sun/
    incubator/olio/workload/php/trunk/src/org/apache/olio/
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/   (with props)
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/driver/   (with props)
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/driver/UIDriver.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/fsloader/   (with props)
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/fsloader/FileLoader.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/harness/   (with props)
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/harness/Web20Benchmark.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/   (with props)
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Address.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Attendees.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Comments.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/EventTag.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Friends.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/LoadController.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Person.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/SocialEvent.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Tag.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/framework/
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/framework/Loadable.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/framework/LoadablePool.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/framework/Loader.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/framework/ThreadConnection.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/framework/ThreadResource.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/olio/
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/   (with props)
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/GrowthTest.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/MemCacheUtility.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/RandomUtil.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/ScaleFactors.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/Scramble.java
    incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/UserName.java
Removed:
    incubator/olio/workload/php/trunk/src/com/
    incubator/olio/workload/php/trunk/src/org/apache/web20/
    incubator/olio/workload/php/trunk/src/org/sun/

Propchange: incubator/olio/workload/php/trunk/src/org/
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/olio/workload/php/trunk/src/org/apache/
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/driver/
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/driver/UIDriver.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/php/trunk/src/org/apache/olio/workload/driver/UIDriver.java?rev=745169&view=auto
==============================================================================
--- incubator/olio/workload/php/trunk/src/org/apache/olio/workload/driver/UIDriver.java (added)
+++ incubator/olio/workload/php/trunk/src/org/apache/olio/workload/driver/UIDriver.java Tue Feb 17 17:43:25 2009
@@ -0,0 +1,1021 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * $Id: UIDriver.java,v 1.1.1.1 2008/09/29 22:33:08 sp208304 Exp $
+ */ 
+package org.apache.olio.workload.driver;
+
+import com.sun.faban.common.NameValuePair;
+import com.sun.faban.common.Utilities;
+import com.sun.faban.driver.*;
+import org.apache.olio.workload.util.RandomUtil;
+import org.apache.olio.workload.util.ScaleFactors;
+import org.apache.olio.workload.util.UserName;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.MultipartPostMethod;
+
+import javax.xml.xpath.XPathExpressionException;
+import java.io.File;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.logging.Logger;
+
+@BenchmarkDefinition (
+    name    = "Web20Bench",
+    version = "0.4",
+    scaleName = "Concurrent Users"
+
+)
+@BenchmarkDriver (
+    name           = "UIDriver",
+    threadPerScale    = 1
+)
+        // 90/10 Read/Write ratio
+       
+@MatrixMix (
+//    operations = {"HomePage", "Login", , "TagSearch", "EventDetail", "PersonDetail",
+//                  "Logout", "AddEvent",  "AddPerson"},
+    operations = { "HomePage", "Login", "TagSearch", "EventDetail", "PersonDetail", "AddPerson", "AddEvent" },
+
+    mix = { @Row({  0, 11, 52, 36,  0, 1,  0 }),
+            @Row({  0,  0, 60, 20,  0, 0, 20 }),
+            @Row({ 21,  6, 41, 31,  0, 1,  0 }),
+            @Row({ 72, 21,  0,  0,  6, 1,  0 }),
+            @Row({ 52,  6,  0, 31, 11, 0,  0 }),
+            @Row({ 0, 0,  0,  0,  100, 0,  0 }),
+            @Row({  0,  0, 0, 100,  0, 0,  0 })
+          }
+)
+@NegativeExponential (
+    cycleType = CycleType.CYCLETIME,
+    cycleMean = 5000,
+    cycleDeviation = 2
+)
+
+public class UIDriver {
+
+    public static final String[] HOME_STATICS = {
+        "/js/tiny_mce/tiny_mce.js",
+        "/js/prototype.js",
+        "/js/effects.js",
+        "/js/dragdrop.js",
+        "/js/controls.js",
+        "/js/application.js",
+        "/css/scaffold.css",
+        "/css/site.css",
+        "/images/bg_main.png",
+        "/images/RSS-icon-large.gif",
+        "/images/php_bg_header.gif",
+        "/images/php_main_nav_link_bg.gif",
+        "/images/php_corner_top_right.gif",
+        "/images/php_corner_top_left.gif",
+        "/images/php_corner_bottom_right.gif",
+        "/images/php_corner_bottom_left.gif",
+        "/images/php_reflec_tile.gif",
+        "/images/php_reflec_right.gif",
+        "/images/php_reflec_left.gif",
+        "/images/php_main_nav_hover_bg.gif"
+    };
+
+    public static final String[] EVENTDETAIL_STATICS = {
+        "/images/php_main_nav_hover_bg.gif",
+        "/js/tiny_mce/tiny_mce.js",
+        "/js/prototype.js",
+        "/js/effects.js",
+        "/js/dragdrop.js",
+        "/js/controls.js",
+        "/js/application.js",
+        "/css/scaffold.css",
+        "/css/site.css",
+        "/images/bg_main.png",
+        "/images/RSS-icon-large.gif",
+        "/images/php_bg_header.gif",
+        "/images/php_main_nav_link_bg.gif",
+        "/js/starrating.js",
+        "/images/php_corner_top_right.gif",
+        "/images/php_corner_top_left.gif",
+        "/images/star_on.png",
+        "/images/star_off.png",
+        "/images/php_corner_bottom_right.gif",
+        "/images/php_corner_bottom_left.gif",
+        "/images/php_reflec_tile.gif",
+        "/images/php_reflec_right.gif",
+        "/images/php_reflec_left.gif"
+    };
+
+    public static final String[] ADDPERSON_STATICS = {
+        "/js/tiny_mce/tiny_mce.js",
+        "/js/prototype.js",
+        "/js/effects.js",
+        "/js/dragdrop.js",
+        "/js/controls.js",
+        "/js/application.js",
+        "/css/scaffold.css",
+        "/css/site.css",
+        "/images/bg_main.png",
+        "/images/RSS-icon-large.gif",
+        "/images/php_bg_header.gif",
+        "/images/php_main_nav_link_bg.gif",
+        "/js/validateform.js",
+        "/images/php_corner_top_right.gif",
+        "/images/php_corner_top_left.gif",
+        "/js/tiny_mce/themes/simple/editor_template.js",
+        "/js/tiny_mce/langs/en.js",
+        "/js/tiny_mce/themes/simple/css/editor_ui.css",
+        "/images/php_corner_bottom_right.gif",
+        "/images/php_corner_bottom_left.gif",
+        "/images/php_reflec_tile.gif",
+        "/images/php_reflec_right.gif",
+        "/images/php_reflec_left.gif",
+        "/js/tiny_mce/themes/simple/images/bold.gif",
+        "/js/tiny_mce/themes/simple/images/italic.gif",
+        "/js/tiny_mce/themes/simple/images/underline.gif",
+        "/js/tiny_mce/themes/simple/images/strikethrough.gif",
+        "/js/tiny_mce/themes/simple/images/separator.gif",
+        "/js/tiny_mce/themes/simple/images/undo.gif",
+        "/js/tiny_mce/themes/simple/images/redo.gif",
+        "/js/tiny_mce/themes/simple/images/cleanup.gif",
+        "/js/tiny_mce/themes/simple/images/bullist.gif",
+        "/js/tiny_mce/themes/simple/images/numlist.gif"
+    };
+
+    public static final String[] ADDEVENT_STATICS = {
+        "/js/tiny_mce/tiny_mce.js",
+        "/js/prototype.js",
+        "/js/effects.js",
+        "/js/dragdrop.js",
+        "/js/controls.js",
+        "/js/application.js",
+        "/css/scaffold.css",
+        "/css/site.css",
+        "/images/bg_main.png",
+        "/images/RSS-icon-large.gif",
+        "/images/php_bg_header.gif",
+        "/images/php_main_nav_link_bg.gif",
+        "/images/php_corner_top_right.gif",
+        "/images/php_corner_top_left.gif",
+        "/js/tiny_mce/themes/simple/editor_template.js",
+        "/js/tiny_mce/langs/en.js",
+        "/js/tiny_mce/themes/simple/css/editor_ui.css",
+        "/js/validateform.js",
+        "/images/php_corner_bottom_right.gif",
+        "/images/php_corner_bottom_left.gif",
+        "/images/php_reflec_tile.gif",
+        "/images/php_reflec_right.gif",
+        "/images/php_reflec_left.gif",
+        "/js/tiny_mce/themes/simple/images/bold.gif",
+        "/js/tiny_mce/themes/simple/images/italic.gif",
+        "/js/tiny_mce/themes/simple/images/underline.gif",
+        "/js/tiny_mce/themes/simple/images/strikethrough.gif",
+        "/js/tiny_mce/themes/simple/images/separator.gif",
+        "/js/tiny_mce/themes/simple/images/undo.gif",
+        "/js/tiny_mce/themes/simple/images/redo.gif",
+        "/js/tiny_mce/themes/simple/images/cleanup.gif",
+        "/js/tiny_mce/themes/simple/images/bullist.gif",
+        "/js/tiny_mce/themes/simple/images/numlist.gif"
+    };
+
+
+    public static final String[] PERSON_STATICS = {
+        "/js/tiny_mce/tiny_mce.js",
+        "/js/prototype.js",
+        "/js/effects.js",
+        "/js/dragdrop.js",
+        "/js/controls.js",
+        "/js/application.js",
+        "/css/scaffold.css",
+        "/css/site.css",
+        "/images/bg_main.png",
+        "/images/RSS-icon-large.gif",
+        "/images/php_bg_header.gif",
+        "/images/php_main_nav_link_bg.gif",
+        "/images/php_corner_top_right.gif",
+        "/images/php_corner_top_left.gif",
+        "/images/php_corner_bottom_right.gif",
+        "/images/php_corner_bottom_left.gif",
+        "/images/php_reflec_tile.gif",
+        "/images/php_reflec_right.gif",
+        "/images/php_reflec_left.gif"
+    };
+
+    
+
+    public static final String[] TAGSEARCH_STATICS = {
+        "/js/tiny_mce/tiny_mce.js",
+        "/js/prototype.js",
+        "/js/effects.js",
+        "/js/dragdrop.js",
+        "/js/controls.js",
+        "/js/application.js",
+        "/css/scaffold.css",
+        "/css/site.css",
+        "/images/bg_main.png",
+        "/images/RSS-icon-large.gif",
+        "/images/php_bg_header.gif",
+        "/images/php_main_nav_link_bg.gif",
+        "/images/php_corner_top_right.gif",
+        "/images/php_corner_top_left.gif",
+        "/images/php_corner_bottom_right.gif",
+        "/images/php_corner_bottom_left.gif",
+        "/images/php_reflec_tile.gif",
+        "/images/php_reflec_right.gif",
+        "/images/php_reflec_left.gif",
+        "/images/php_main_nav_hover_bg.gif"
+    };
+
+    // We just need today's date. java.sql.date does not have any time anyway.
+    public static final java.sql.Date BASE_DATE =
+                                new java.sql.Date(System.currentTimeMillis());
+
+    private DriverContext ctx;
+    private HttpTransport http;
+    private String baseURL;
+    private String personDetailURL;
+    private String tagSearchURL;
+    private String homepageURL, loginURL, logoutURL;
+    private String addEventURL, addPersonURL, eventDetailURL;
+    private String addEventResultURL, addPersonResultURL;
+    private String addAttendeeURL; //GET update.php?id=$eventid
+    // private String updatePageURL; //POST gettextafterinsert.php list=attendees
+    private String fileServiceURL;
+    private String[] homepageStatics, personStatics, personGets,
+    tagSearchStatics, eventDetailStatics, addPersonStatics, addEventStatics;
+    File eventImg, eventThumb, eventPdf, personImg, personThumb;
+    private boolean isLoggedOn = false;
+    private String username;
+    Logger logger;
+    private com.sun.faban.driver.util.Random random;
+    private DateFormat df;
+    private String selectedEvent;
+    private int personsAdded = 0;
+    private int loadedUsers;
+    private boolean isCached;
+    private HashSet<String> cachedURLs = new HashSet<String>();
+    private LinkedHashMap<String, String> loginHeaders =
+            new LinkedHashMap<String, String>();
+    private UIDriverMetrics driverMetrics;
+    private long imgBytes = 0;
+    private int imagesLoaded = 0;
+    private String tagCloudURL;
+    private StringBuilder tags = new StringBuilder();
+    private LinkedHashSet<Integer> tagSet = new LinkedHashSet<Integer>(7);
+
+    public UIDriver() throws XPathExpressionException {
+        ctx = DriverContext.getContext();
+        int scale = ctx.getScale();
+        ScaleFactors.setActiveUsers(scale);
+        http = new HttpTransport();
+        // http.setFollowRedirects(true);
+        logger = ctx.getLogger();
+        random = ctx.getRandom();
+        driverMetrics = new UIDriverMetrics();
+        ctx.attachMetrics(driverMetrics);
+        String hostPorts = ctx.getXPathValue(
+                                "/web20/webServer/fa:hostConfig/fa:hostPorts");
+        List<NameValuePair<Integer>> hostPortList =
+                                            Utilities.parseHostPorts(hostPorts);
+        int loadedScale = Integer.parseInt(
+                                    ctx.getXPathValue("/web20/dbServer/scale"));
+        loadedUsers = ScaleFactors.USERS_RATIO * loadedScale;
+        if (scale > loadedScale)
+            throw new FatalException("Data loaded only for " + loadedScale +
+                    " concurrent users. Run is set for " + scale +
+                    " concurrent users. Please load for enough concurrent " +
+                    "users. Run terminating!");
+
+        String type = ctx.getProperty("serverType");
+        String resourcePath = ctx.getResourceDir();
+        if (!resourcePath.endsWith(File.separator))
+            resourcePath += File.separator;
+        eventImg = new File(resourcePath + "event.jpg");
+        // logger.info("eventImg: " + eventImg);
+        eventThumb = new File(resourcePath + "event_thumb.jpg");
+        // logger.info("eventThumb: " + eventThumb);
+        eventPdf = new File(resourcePath + "event.pdf");
+        // logger.info("eventPdf: " + eventPdf);
+        personImg = new File(resourcePath + "person.jpg");
+        // logger.info("personImg: " + personImg);
+        personThumb = new File(resourcePath + "person_thumb.jpg");
+        // logger.info("personThumb: " + personThumb);
+
+        int bucket = Utilities.selectBucket(ctx.getThreadId(),
+                            ctx.getClientsInDriver(), hostPortList.size());
+        NameValuePair<Integer> hostPort = hostPortList.get(bucket);
+
+        if (hostPort.value == null)
+            baseURL = "http://" + hostPort.name;
+        else
+            baseURL = "http://" + hostPort.name + ':' + hostPort.value;
+
+        personDetailURL = baseURL + "/users." + type + "?username=";
+        tagSearchURL = baseURL + "/taggedEvents." + type;
+        tagCloudURL = baseURL + "/taggedEvents." + type;
+        addEventURL = baseURL + "/addEvent." + type;
+        addEventResultURL = baseURL + "/addEventResult." + type;
+        addPersonURL = baseURL + "/addPerson." + type;
+        addPersonResultURL = baseURL + "/addPersonResult." + type;
+        homepageURL = baseURL + "/index." + type;
+        loginURL = baseURL + "/login." + type;
+        logoutURL = baseURL + "/logout." + type;
+        addAttendeeURL = baseURL + "/addAttendee." + type + "?id=";
+        // updatePageURL = baseURL + "/gettextafterinsert." + type;
+        eventDetailURL = baseURL + "/events." + type + "?socialEventID=";
+        fileServiceURL = baseURL + "/fileService." + type + '?';
+
+        homepageStatics = populateList(HOME_STATICS);
+        personStatics = populateList(PERSON_STATICS);
+        tagSearchStatics = populateList(TAGSEARCH_STATICS);
+        eventDetailStatics = populateList(EVENTDETAIL_STATICS);
+        addPersonStatics = populateList(ADDPERSON_STATICS);
+        addEventStatics = populateList(ADDEVENT_STATICS);
+
+        if (hostPort.value == null)
+            loginHeaders.put("Host", hostPort.name);
+        else
+            loginHeaders.put("Host", hostPort.name + ':' + hostPort.value);
+
+        loginHeaders.put("User-Agent", "Mozilla/5.0");
+        loginHeaders.put("Accept", "text/xml.application/xml,application/" +
+                "xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;" +
+                "q=0.5");
+        loginHeaders.put("Accept-Language", "en-us,en;q=0.5");
+        loginHeaders.put("Accept-Encoding", "gzip,deflate");
+        loginHeaders.put("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
+        loginHeaders.put("Keep-Alive", "300");
+        loginHeaders.put("Connection", "keep-alive");
+        loginHeaders.put("Referer", homepageURL);
+
+        isLoggedOn = false;
+        isCached = cached();
+    }
+
+    @BenchmarkOperation (
+        name    = "HomePage",
+        max90th = 1,
+        timing  = Timing.AUTO
+    )
+    public void doHomePage() throws IOException {
+        logger.finer("HomePage: Accessing " + homepageURL);
+
+        http.fetchURL(homepageURL);
+        imgBytes = 0;
+        imagesLoaded = 0;
+
+        StringBuilder responseBuffer = http.getResponseBuffer();
+        if (responseBuffer.length() == 0)
+            throw new IOException("Received empty response");
+
+        Set<String> images = parseImages(responseBuffer);
+        if (!isCached) {
+
+            // Fetch the CSS/JS files
+
+            loadStatics(homepageStatics);
+        }
+        loadImages(images);
+        selectedEvent = RandomUtil.randomEvent(random, responseBuffer);
+        logger.finer("Images loaded: " + imagesLoaded);
+        logger.finer("Image bytes loaded: " + imgBytes);
+        if (ctx.isTxSteadyState())
+            driverMetrics.homePageImages += images.size();
+            driverMetrics.homePageImagesLoaded += imagesLoaded;
+            driverMetrics.homePageImageBytes += imgBytes;
+    }
+
+    @BenchmarkOperation (
+        name    = "Login",
+        max90th = 1,
+        timing  = Timing.AUTO
+    )
+    public void doLogin() throws IOException, Exception {
+        logger.finer("In doLogin");
+        int randomId = 0; //use as password
+        username = null;
+
+        if (!isLoggedOn) {
+            randomId = selectUserID();
+            username = UserName.getUserName(randomId);
+            logger.fine("Logging in as " + username + ", " + randomId);
+            http.readURL(loginURL, constructLoginPost(randomId), loginHeaders);
+            // This redirects to home.
+            http.fetchURL(homepageURL);
+          
+            int loginIdx = http.getResponseBuffer().indexOf("Username");
+            if (loginIdx != -1){
+                throw new RuntimeException("Found login prompt at index " + loginIdx + ", Login as " + username + ", " +
+                                                        randomId + " failed.");
+                //throw new Exception("Found login prompt at index " + loginIdx); 
+            }
+            
+            /*
+            if (http.getResponseBuffer().indexOf("Login:") != 1290) {
+                logger.finest(http.getResponseBuffer().toString());
+                //throw new RuntimeException("Index of LOGIN = " +http.getResponseBuffer().indexOf("Login:") );
+                //logger.info(http.getResponseBuffer().toString());
+                logger.info("Index of LOGIN = " +http.getResponseBuffer().indexOf("Login:") );
+                throw new RuntimeException("Login as " + username + ", " +
+                                                        randomId + " failed.");
+            }
+            */
+            isLoggedOn=true;
+            logger.fine("Login successful as " + username + ", " + randomId);
+        } else {
+            //already logged in --> logout,then log in again
+            doLogout();
+            doLogin();
+        }
+    }
+
+
+    @BenchmarkOperation (
+        name    = "Logout",
+        max90th = 1,
+        timing  = Timing.AUTO
+    )
+    public void doLogout() throws IOException {
+        if (isLoggedOn){
+            logger.finer("Logging off = " + isLoggedOn);
+            http.fetchURL(logoutURL);
+            cachedURLs.clear();
+            isCached = cached();
+            isLoggedOn=false;
+            http = new HttpTransport(); // clear all state
+        }
+    }
+
+
+    @BenchmarkOperation (
+        name    = "TagSearch",
+        max90th = 2,
+        timing  = Timing.AUTO
+    )
+    public void doTagSearch() throws IOException {
+        String tag = RandomUtil.randomTagName(random);
+        int count = random.random(100, 150);
+        String post = "tag=" + tag + "&tagsearchsubmit=Search+Tags";
+        logger.finer("TagSearch: " + tagSearchURL + " Post: " + post);
+        http.readURL(tagSearchURL, post);
+        //if (http.getResponseCode() != 302)
+        //    logger.warning("Tag search response not redirecting.");
+      
+        http.fetchURL(tagCloudURL + "?tag=" + tag + "&count=" + count);
+        StringBuilder responseBuffer = http.getResponseBuffer();
+        if (responseBuffer.length() == 0)
+            throw new IOException("Received empty response");
+        Set<String> images = parseImages(responseBuffer);
+        loadStatics(tagSearchStatics);
+        loadImages(images);
+        String event = RandomUtil.randomEvent(random, responseBuffer);
+        if (event != null)
+            selectedEvent = event;
+        if (ctx.isTxSteadyState())
+            driverMetrics.tagSearchImages += images.size();
+    }
+
+    @BenchmarkOperation (
+        name    = "AddEvent",
+        max90th = 4,
+        timing  = Timing.MANUAL
+    )
+    public void doAddEvent() throws IOException {
+        logger.finer("doAddEvent");
+        ctx.recordTime();
+        http.readURL(addEventURL);
+        loadStatics(addEventStatics);
+
+        MultipartPostMethod post = new MultipartPostMethod(addEventResultURL);
+        if(isLoggedOn) {
+            String[] parameters = prepareEvent();
+            if (parameters[0] == null || parameters[0].length() == 0)
+                logger.warning("Socialevent title is null!");
+            else
+                logger.finer("addEvent adding event title: " + parameters[0]);
+            
+            post.addParameter("title", parameters[0]);
+            post.addParameter("description", parameters[1]);
+            post.addParameter("telephone", parameters[3]);
+            post.addParameter("timezone", parameters[4]);
+            //add the address
+            String[] addressArr = prepareAddress();
+            post.addParameter("street1", addressArr[0]);
+            post.addParameter("street2", addressArr[1]);
+            post.addParameter("city", addressArr[2]);
+            post.addParameter("state", addressArr[3]);
+            post.addParameter("zip", addressArr[4]);
+            post.addParameter("country", addressArr[5]);
+            post.addParameter("year",parameters[5]);
+            post.addParameter("month", parameters[6]);
+            post.addParameter("day", parameters[7]);
+            post.addParameter("hour", parameters[8]);
+            post.addParameter("minute", parameters[9]);
+            post.addParameter("tags", parameters[2]);
+            post.addParameter("submitter_user_name", username);
+            // We do the images last, not to split the fields into parts
+            post.addParameter("upload_image", eventImg);
+//            post.addParameter("eventThumbnail", eventThumb);
+            post.addParameter("upload_literature",eventPdf);
+            post.addParameter("addeventsubmit", "Create");
+
+            doMultiPartPost(post);
+        }
+        ctx.recordTime();
+        ++driverMetrics.addEventTotal;
+    }
+
+    @BenchmarkOperation (
+        name    = "AddPerson",
+        max90th = 3,
+        timing  = Timing.MANUAL
+    )
+    public void doAddPerson() throws IOException {
+        logger.finer("doAddPerson");
+        if (isLoggedOn)
+            doLogout();
+
+        ctx.recordTime();
+        http.readURL(addPersonURL);
+        loadStatics(addPersonStatics);
+        MultipartPostMethod post = new MultipartPostMethod(addPersonResultURL);
+        String[] parameters = preparePerson();
+        
+        // Debug
+        if (parameters[0] == null || parameters[0].length() == 0)
+            logger.warning("Username is null!");
+        else
+            logger.finer("addPerson adding user: " + parameters[0]);
+        
+        post.addParameter("add_user_name", parameters[0]);
+        post.addParameter("psword", parameters[1]);
+        post.addParameter("passwordx", parameters[1]);
+        post.addParameter("first_name", parameters[2]);
+        post.addParameter("last_name", parameters[3]);
+        post.addParameter("email",parameters[4]);
+        String[] addressArr = prepareAddress();
+        post.addParameter("street1",addressArr[0]);
+        post.addParameter("street2",addressArr[1]);
+        post.addParameter("zip", addressArr[4]);
+        post.addParameter("city", addressArr[2]);
+        post.addParameter("state", addressArr[3]);
+        post.addParameter("country", addressArr[5]);
+        post.addParameter("telephone",parameters[5]);
+        post.addParameter("timezone", parameters[7]);
+        post.addParameter("user_image", personImg);
+//        post.addParameter("user_thumbnail",personThumb);
+        post.addParameter("summary", parameters[6]);
+        post.addParameter("addpersonsubmit", "Create");
+        doMultiPartPost(post);
+        ctx.recordTime();
+        ++driverMetrics.addPersonTotal;
+    }
+
+    @BenchmarkOperation (
+        name    = "EventDetail",
+        max90th = 2,
+        timing  = Timing.AUTO
+    )
+    public void doEventDetail() throws IOException {
+        //select random event
+        logger.finer("doEventDetail");
+            http.fetchURL(eventDetailURL + selectedEvent);
+        StringBuilder responseBuffer = http.getResponseBuffer();
+        if (responseBuffer.length() == 0)
+            throw new IOException("Received empty response");
+        boolean canAddAttendee = isLoggedOn &&
+                                responseBuffer.indexOf("Attend") != -1;
+//        if (isLoggedOn && !canAddAttendee)
+//            logger.warning(responseBuffer.toString());
+        Set<String> images = parseImages(responseBuffer);
+        loadStatics(eventDetailStatics);
+        loadImages(images);
+        int card = -1;
+        if (canAddAttendee) {
+            // 10% of the time we can add ourselves, we will.
+            card = random.random(0, 9);
+            if (card == 0)
+                doAddAttendee();
+        }
+
+        if (ctx.isTxSteadyState()) {
+            driverMetrics.eventDetailImages += images.size();
+            if (canAddAttendee) {
+                ++driverMetrics.addAttendeeReadyCount;
+                if (card == 0)
+                    ++driverMetrics.addAttendeeCount;
+            }
+        }
+    }
+
+    @BenchmarkOperation (
+        name = "PersonDetail",
+        max90th = 2,
+        timing = Timing.AUTO
+    )
+    public void doPersonDetail() throws IOException {
+        logger.finer("doPersonDetail");
+        StringBuilder buffer = new StringBuilder(fileServiceURL.length() + 20);
+        
+        // TODO: account for new users when loading images, too.
+        buffer.append(fileServiceURL).append("file=p");
+        int id = random.random(1, ScaleFactors.users);
+        http.fetchURL(personDetailURL + UserName.getUserName(id));
+        StringBuilder responseBuffer = http.getResponseBuffer();
+        if (responseBuffer.length() == 0)
+            throw new IOException("Received empty response");
+
+        loadStatics(personStatics);       
+        http.readURL(buffer.append(id).append(".jpg").toString());
+    }
+
+    public void doAddAttendee() throws IOException {
+        //can only add yourself (one attendee) to party
+        http.readURL(addAttendeeURL + selectedEvent);
+        // http.readURL(updatePageURL, "list=attendees");
+    }
+
+    public Set<String> parseImages(StringBuilder buffer) {
+        LinkedHashSet<String> urlSet = new LinkedHashSet<String>();
+        String elStart = "<img ";
+        String attrStart = " src=\"";
+        int elStartLen = elStart.length() - 1; // Don't include the trailing space
+        int attrStartLen = attrStart.length();
+        int idx = 0;
+        logger.finest("Parsing images from buffer");
+        for (;;) {
+
+            // Find and copy out the element.
+            idx = buffer.indexOf(elStart, idx);
+            if (idx == -1)
+                break;
+            idx += elStartLen;
+            int endIdx = buffer.indexOf("/>", idx);
+            if (endIdx == -1)
+                break;
+            String elText = buffer.substring(idx, endIdx);
+            idx = endIdx + 1;
+
+            // Find the attribute
+            int idx2 = elText.indexOf(attrStart);
+            if (idx2 == -1) {
+                logger.finer("No img src attribute. Weird! " + elText);
+                continue;
+            }
+            endIdx = elText.indexOf("\"", idx2 + attrStartLen);
+            if (endIdx == -1) {
+                logger.warning("No img src attribute ending. Weird! " + elText);
+                continue;
+            }
+
+            String link = elText.substring(idx2 + attrStartLen, endIdx);
+            if (link.startsWith("fileService.")) {
+                String url = baseURL + '/' + link;
+
+                logger.finest("Adding " + url + " from idx " + idx);
+                urlSet.add(url);
+            }
+        }
+        return urlSet;
+    }
+
+    private void loadImages(Set<String> images) throws IOException {
+        if (images != null)
+            for (String image : images)
+                // Loads image only if not cached, means we can add to cache.
+                if (cachedURLs.add(image)) {
+                    logger.finer("Loading image " + image);
+                    int imgSize = http.readURL(image);
+                    if (imgSize < 1024) {
+                        logger.warning("Image at " + image + " size of " +
+                                        imgSize + " bytes is too small. " +
+                                        "Image may not exist");
+                    }
+                    imgBytes += imgSize;
+                    ++imagesLoaded;
+                } else {
+                    logger.finer("Image already cached: Not loading " + image);
+                }
+    }
+
+    private boolean cached() {
+        // We have to decide whether the cache is empty or not.
+        // 40% of the time, it is empty.
+        boolean cached = true;
+        int selector = random.random(0, 9);
+        if (selector < 4) {
+            cached = false;
+        }
+        return cached;
+    }
+
+    private void loadStatics(String[] urls) throws IOException {
+
+        if (!isCached)
+            for (String url : urls)
+                if (cachedURLs.add(url)) {
+                    logger.finer("Loading URL " + url);
+                    http.readURL(url);
+                } else {
+                    logger.finer("URL already cached: Not loading " + url);
+                }
+    }
+
+    public DateFormat getDateFormat() {
+        if (df == null)
+            df = new SimpleDateFormat("yyyy-MM-dd-HH-mm");
+        return df;
+    }
+
+    public int selectUserID() {
+        return random.random(0, ScaleFactors.USERS_RATIO - 1) *
+                            ScaleFactors.activeUsers + ctx.getThreadId() + 1;
+    }
+
+
+    private String[] populateList(String[] arrList) {
+
+        String[] returnList = new String[arrList.length];
+        if (arrList != null) {
+
+            try {
+                for (int i = 0; i < arrList.length; i++) {
+                    returnList[i] = baseURL + arrList[i].trim();
+
+                }
+            } catch (Exception e) {
+                System.out.println ("Exception - " + e);
+                e.printStackTrace();
+            }
+        }
+        return returnList;
+    }
+
+    private String constructLoginPost(int randomId) {
+        return "user_name=" + username + "&password=" +
+                String.valueOf(randomId) + "&submit=Login";
+    }
+
+    public void doMultiPartPost(MultipartPostMethod post) throws IOException {
+
+        HttpClient client = new HttpClient();
+        client.setConnectionTimeout(5000);
+        int status = client.executeMethod(post);
+        if(status != HttpStatus.SC_OK)
+            throw new IOException("Multipart Post did not work");
+    }
+
+    public String[] prepareEvent()  {
+
+        String fields[]  = new String[10];
+        StringBuilder buffer = new StringBuilder(256);
+        fields[0] = RandomUtil.randomText(random, 15, 20); //title
+        fields[1] = RandomUtil.randomText(random, 50, 495); // description
+
+        int numTags = random.random(1, 7); // Avg is 4 tags per event
+        for (int i = 0; i < numTags; i++)
+            while (!tagSet.add(RandomUtil.randomTagId(random, 0.1d)));
+
+        for (int tagId : tagSet)
+            tags.append(UserName.getUserName(tagId)).append(' ');
+        tags.setLength(tags.length() - 1);
+
+        fields[2]= tags.toString();
+        tags.setLength(0);
+        tagSet.clear();
+
+        fields[3]= RandomUtil.randomPhone(random, buffer); //phone
+        fields[4]= RandomUtil.randomTimeZone(random); // timezone
+        DateFormat dateFormat = getDateFormat(); // eventtimestamp
+        String dateTime = dateFormat.format( //eventtimestamp
+                random.makeDateInInterval(BASE_DATE, 0, 540));
+        StringTokenizer t = new StringTokenizer(dateTime, "-");
+        int i = 5;
+        while (t.hasMoreTokens()) {
+            fields[i++] = t.nextToken();
+        }
+        return fields;
+    }
+
+    public String[] prepareAddress() {
+
+        String[] STREETEXTS = { "Blvd", "Ave", "St", "Ln", "" };
+        StringBuilder buffer = new StringBuilder(255);
+        buffer.append(random.makeNString(1, 5)).append(' '); // number
+        RandomUtil.randomName(random, buffer, 1, 11); // street
+        String streetExt = STREETEXTS[random.random(0, STREETEXTS.length - 1)];
+        if (streetExt.length() > 0)
+            buffer.append(' ').append(streetExt);
+        String[] fields = new String[6];
+        fields[0] = buffer.toString();
+
+        int toggle = random.random(0, 1); // street2
+        if (toggle > 0)
+            fields[1] = random.makeCString(5, 20);
+        else
+            fields[1] = "";
+
+        fields[2] = random.makeCString(4, 14); // city
+        fields[3] = random.makeCString(2, 2).toUpperCase(); // state
+        fields[4] = random.makeNString(5, 5);  // zip
+
+        toggle = random.random(0, 1);
+        if (toggle == 0) {
+            fields[5] = "USA";
+        } else {
+            buffer.setLength(0);
+            fields[5] = RandomUtil.randomName(random, buffer, 6, 16).toString();
+        }
+        return fields;
+    }
+
+    public String[] preparePerson() {
+        String fields[]  = new String[8];
+        StringBuilder b = new StringBuilder(256);
+        int id = loadedUsers + personsAdded++ * ScaleFactors.activeUsers +
+                                                        ctx.getThreadId() + 1;
+        fields[0] = UserName.getUserName(id);
+        //use the same field for repeating the password field.
+        fields[1] = String.valueOf(id);
+        fields[2] = RandomUtil.randomName(random, b, 2, 12).toString();
+        b.setLength(0);
+        fields[3] = RandomUtil.randomName(random, b, 5, 15).toString();
+        fields[4] = random.makeCString(3, 10);
+        fields[4] = fields[2] + '_' + fields[3] + '@' + fields[4] + ".com";
+        b.setLength(0);
+        fields[5] = RandomUtil.randomPhone(random, b);
+        fields[6] = random.makeAString(250, 2500);
+        fields[7] = RandomUtil.randomTimeZone(random);
+        return fields;
+    }
+
+    static class UIDriverMetrics implements CustomMetrics {
+
+        int addAttendeeCount = 0;
+        int addAttendeeReadyCount = 0;
+        int homePageImages = 0;
+        int tagSearchImages = 0;
+        int eventDetailImages = 0;
+        int homePageImagesLoaded = 0;
+        long homePageImageBytes = 0;
+        int addEventTotal = 0;
+        int addPersonTotal = 0;
+
+        public void add(CustomMetrics other) {
+            UIDriverMetrics o = (UIDriverMetrics) other;
+            addAttendeeCount += o.addAttendeeCount;
+            addAttendeeReadyCount += o.addAttendeeReadyCount;
+            homePageImages += o.homePageImages;
+            tagSearchImages += o.tagSearchImages;
+            eventDetailImages += o.eventDetailImages;
+            homePageImageBytes += o.homePageImageBytes;
+            homePageImagesLoaded += o.homePageImagesLoaded;
+            addEventTotal += o.addEventTotal;
+            addPersonTotal += o.addPersonTotal;
+        }
+
+        public Element[] getResults() {
+            Result r = Result.getInstance();
+            int total = r.getOpsCountSteady("EventDetail");
+            Element[] el = new Element[10];
+            el[0] = new Element();
+            el[0].description = "% EventDetail views where attendee added";
+            el[0].target = "&gt;= 6";
+            if (total > 0) {
+                double pctAdd = 100d * addAttendeeCount / (double) total;
+                el[0].result = String.format("%.2f", pctAdd);
+                if (pctAdd >= 6d)
+                    el[0].passed = Boolean.TRUE;
+                else
+                    el[0].passed = Boolean.FALSE;
+            } else {
+                el[0].result = "";
+                el[0].passed = Boolean.FALSE;
+            }
+
+            el[1] = new Element();
+            el[1].description = "EventDetail count where attendee can be added";
+            el[1].result = String.valueOf(addAttendeeReadyCount);
+
+            int cnt = r.getOpsCountSteady("HomePage");
+            el[2] = new Element();
+            el[2].description = "Average images references on Home Page";
+            el[2].target = "10";
+            el[2].allowedDeviation = "0.5";
+            if (cnt > 0) {
+                double imagesPerPage = homePageImages / (double) cnt;
+                el[2].result = String.format("%.2f", imagesPerPage);
+                if (imagesPerPage >= 9.5d && imagesPerPage <= 10.5d)
+                    el[2].passed = Boolean.TRUE;
+                else
+                    el[2].passed = Boolean.FALSE;
+            } else {
+                el[2].result = "";
+                el[2].passed = Boolean.FALSE;
+            }
+
+            el[3] = new Element();
+            el[3].description = "Average images loaded per Home Page";
+            el[3].target = "&gt;= 3";
+            if (cnt > 0) {
+                double avgImgs = homePageImagesLoaded / (double) cnt;
+                el[3].result = String.format("%.2f", avgImgs);
+                if (avgImgs >= 3d)
+                    el[3].passed = Boolean.TRUE;
+                else
+                    el[3].passed = Boolean.FALSE;
+            } else {
+                el[3].result = "";
+                el[3].passed = Boolean.FALSE;
+            }
+
+            el[4] = new Element();
+            el[4].description = "Average image bytes received per Home Page";
+            el[4].target = "&gt;= 15000";
+            if (cnt > 0) {
+                double avgBytes = homePageImageBytes / (double) cnt;
+                el[4].result = String.format("%.2f", avgBytes);
+                if (avgBytes >= 15000)
+                    el[4].passed = Boolean.TRUE;
+                else
+                    el[4].passed = Boolean.FALSE;
+            } else {
+                el[4].result = "";
+                el[4].passed = Boolean.FALSE;
+            }
+            cnt = r.getOpsCountSteady("TagSearch");
+            el[5] = new Element();
+            el[5].description = "Average images on Tag Search Results";
+            el[5].target = "&gt;= 3.6";
+            if (cnt > 0) {
+                double avgImgs = tagSearchImages / (double) cnt;
+                el[5].result = String.format("%.2f", avgImgs);
+                if (avgImgs >= 3.6d)
+                    el[5].passed = Boolean.TRUE;
+                else
+                    el[5].passed = Boolean.FALSE;
+            } else {
+                el[5].result = "";
+                el[5].passed = Boolean.FALSE;
+            }
+            el[6] = new Element();
+            el[6].description = "Average images on Event Detail";
+            el[6].target = "&gt;= 1";
+            if (total > 0) {
+                double avgImgs = eventDetailImages / (double) total;
+                el[6].result = String.format("%.2f", avgImgs);
+                if (avgImgs >= 1d)
+                    el[6].passed = Boolean.TRUE;
+                else
+                    el[6].passed = Boolean.FALSE;
+            } else {
+                el[6].result = "";
+                el[6].passed = Boolean.FALSE;
+            }
+            el[7] = new Element();
+            el[7].description = "Total successful AddEvent calls";
+            el[7].result = String.valueOf(addEventTotal);
+            el[8] = new Element();
+            el[8].description = "Total successful AddPerson calls";
+            el[8].result = String.valueOf(addPersonTotal);
+            el[9] = new Element();
+            el[9].description = "Concurrent user to ops/sec ratio";
+            el[9].target = "&lt;= 5.25";
+            double ratio = r.getScale() / r.getMetric();
+            el[9].result = String.format("%.2f", ratio);
+            if (ratio <= 5.25d)
+                el[9].passed = true;
+            else
+                el[9].passed = false;
+            return el;
+        }
+
+        public Object clone() {
+            UIDriverMetrics clone = new UIDriverMetrics();
+            clone.addAttendeeCount = addAttendeeCount;
+            clone.addAttendeeReadyCount = addAttendeeReadyCount;
+            clone.homePageImages = homePageImages;
+            clone.tagSearchImages = tagSearchImages;
+            clone.eventDetailImages = eventDetailImages;
+            clone.homePageImageBytes = homePageImageBytes;
+            clone.homePageImagesLoaded = homePageImagesLoaded;
+            clone.addEventTotal = addEventTotal;
+            clone.addPersonTotal = addPersonTotal;
+            return clone;
+        }
+    }
+}

Propchange: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/fsloader/
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/fsloader/FileLoader.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/php/trunk/src/org/apache/olio/workload/fsloader/FileLoader.java?rev=745169&view=auto
==============================================================================
--- incubator/olio/workload/php/trunk/src/org/apache/olio/workload/fsloader/FileLoader.java (added)
+++ incubator/olio/workload/php/trunk/src/org/apache/olio/workload/fsloader/FileLoader.java Tue Feb 17 17:43:25 2009
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ *  $Id: FileLoader.java,v 1.1.1.1 2008/09/29 22:33:08 sp208304 Exp $
+ */
+
+package org.apache.olio.workload.fsloader;
+
+import org.apache.olio.workload.util.ScaleFactors;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.channels.FileChannel;
+import java.util.Formatter;
+import java.util.ArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+public class FileLoader {
+
+    private static Logger logger = Logger.getLogger(FileLoader.class.getName());
+
+    public static void main(String[] args) throws Exception {
+        String srcDir = args[0];
+        String destDir = args[1];
+        ScaleFactors.setActiveUsers(Integer.parseInt(args[2]));
+        srcDir += File.separator;
+
+        // Clear the dest dir
+        File dest = new File(destDir);
+        if (!dest.isDirectory()) {
+            logger.severe(destDir + " Not a directory!");
+            System.exit(1);
+        }
+
+        logger.info("Deleting files in " + destDir);
+        File[] list = dest.listFiles();
+        for (File f : list) {
+            String name = f.getName();
+            boolean delete = false;
+            if (name.endsWith(".jpg"))
+                delete = true;
+            else if (name.endsWith(".JPG"))
+                delete = true;
+            else if (name.endsWith(".pdf"))
+                delete = true;
+            else if (name.endsWith(".PDF"))
+                delete = true;
+            if (delete && !f.delete())
+                logger.warning("Error deleting file " + f.getName());
+        }
+
+        ArrayList<LoaderThread> loaders = new ArrayList<LoaderThread>();
+
+        loaders.add(new LoaderThread(srcDir + "person.jpg",
+                destDir + File.separator + "p%d.jpg", ScaleFactors.users));
+        loaders.add(new LoaderThread(srcDir + "person_thumb.jpg",
+                destDir + File.separator + "p%dt.jpg", ScaleFactors.users));
+        loaders.add(new LoaderThread(srcDir + "event.jpg",
+                destDir + File.separator + "e%d.jpg", ScaleFactors.events));
+        loaders.add(new LoaderThread(srcDir + "event_thumb.jpg",
+                destDir + File.separator + "e%dt.jpg", ScaleFactors.events));
+        loaders.add(new LoaderThread(srcDir + "event.pdf",
+                destDir + File.separator + "e%d.pdf", ScaleFactors.events));
+
+        for (LoaderThread loader : loaders) {
+            loader.join();
+        }
+
+        for (LoaderThread loader : loaders) {
+            loader.close();
+        }
+
+        System.exit(0);
+/*
+        FileChannel img = new FileInputStream(
+                                    srcDir + "person.jpg").getChannel();
+        FileChannel thumb = new FileInputStream(
+                                    srcDir + "person_thumb.jpg").getChannel();
+        long imgSize = img.size();
+        long thumbSize = thumb.size();
+
+        logger.info("Loading user images...");
+        for (int i = 1; i <= ScaleFactors.users; i++) {
+            logger.finer("Loading files for user " + i);
+            copyTo(img, imgSize, destDir + File.separator + "p" + i + ".jpg");
+            copyTo(thumb, thumbSize,
+                    destDir + File.separator + "p" + i + "t.jpg");
+        }
+
+        img.close();
+        thumb.close();
+
+        logger.info("Loading event images and files...");
+        img = new FileInputStream(srcDir + "event.jpg").getChannel();
+        thumb = new FileInputStream(srcDir + "event_thumb.jpg").getChannel();
+        FileChannel lit = new FileInputStream(
+                                    srcDir + "event.pdf").getChannel();
+
+        imgSize = img.size();
+        thumbSize = thumb.size();
+        long litSize = lit.size();
+
+        for (int i = 1; i <= ScaleFactors.events; i++) {
+            logger.finer("Loading files for event " + i);
+            copyTo(img, imgSize, destDir + File.separator + "e" + i + ".jpg");
+            copyTo(thumb, thumbSize,
+                    destDir + File.separator + "e" + i + "t.jpg");
+            copyTo(lit, litSize, destDir + File.separator + "e" + i + ".pdf");
+        }
+
+        img.close();
+        thumb.close();
+        lit.close();
+        System.exit(0);
+*/
+    }
+
+    /*
+    private static void copyTo(FileChannel src, long size, String destFile)
+            throws IOException {
+        FileChannel dest = (new FileOutputStream(destFile)).getChannel();
+        src.transferTo(0, size, dest);
+        dest.close();
+    }
+    */
+
+    static class LoaderThread extends Thread {
+
+        FileChannel src;
+        int count;
+        long size;
+        String pattern;
+        Formatter format;
+
+        public LoaderThread(String src, String destPattern, int count)
+                throws IOException {
+            this.src = new FileInputStream(src).getChannel();
+            size = this.src.size();
+            this.count = count;
+            this.pattern = destPattern;
+            format = new Formatter();
+            start();
+        }
+
+        public void run() {
+            for (int i = 1; i <= count; i++) {
+                String dest = format.format(pattern, i).toString();
+                if (i % 1000 == 0) {
+                    logger.info("Copying to " + dest);
+                }
+                ((StringBuilder) format.out()).setLength(0);
+                try {
+                    FileChannel destChannel = new FileOutputStream(dest).
+                                                            getChannel();
+                    src.transferTo(0, size, destChannel);
+                    destChannel.close();
+                } catch (IOException e) {
+                    logger.log(Level.WARNING, "Error writing file " + dest, e);
+                }
+            }
+        }
+
+        public void close() throws IOException {
+            src.close();
+        }
+    }
+}

Propchange: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/harness/
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/harness/Web20Benchmark.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/php/trunk/src/org/apache/olio/workload/harness/Web20Benchmark.java?rev=745169&view=auto
==============================================================================
--- incubator/olio/workload/php/trunk/src/org/apache/olio/workload/harness/Web20Benchmark.java (added)
+++ incubator/olio/workload/php/trunk/src/org/apache/olio/workload/harness/Web20Benchmark.java Tue Feb 17 17:43:25 2009
@@ -0,0 +1,231 @@
+/* Copyright ?? 2008 Sun Microsystems, Inc. All rights reserved
+ *
+ * Use is subject to license terms.
+ *
+ * $Id: Web20Benchmark.java,v 1.1.1.1 2008/09/29 22:33:08 sp208304 Exp $
+ */
+package com.sun.web20.harness;
+
+import com.sun.faban.common.Command;
+import com.sun.faban.common.CommandHandle;
+import com.sun.faban.common.NameValuePair;
+import com.sun.faban.harness.DefaultFabanBenchmark;
+import com.sun.faban.harness.RunContext;
+import com.sun.faban.harness.engine.*;
+
+import java.io.File;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.logging.Logger;
+
+import static com.sun.faban.harness.RunContext.*;
+
+/**
+ * Harness hook for the sample web benchmark. This class is not needed
+ * for benchmarks implemented using the Faban Driver Framework if the
+ * default behavior is sufficient. We just show the hooks you can
+ * customize in this class. If the default behavior is desired, you can
+ * leave out the benchmark-class element in benchmark.xml.
+ *
+ * @author Akara Sucharitakul
+ */
+public class Web20Benchmark extends DefaultFabanBenchmark {
+    
+    static Logger logger = Logger.getLogger(
+                                        Web20Benchmark.class.getName());
+    int totalRunningTimeInSecs = 0;
+    private List<NameValuePair<Integer>> memcacheServers;
+    private String webServerBinPath, webServerLogPath, webServerConfPath;
+    private String webServerPidPath, phpIniPath, cacheBinPath, dbConfPath;
+    WebServerService webServerService;
+    MemcachedService memcachedService = MemcachedService.getHandle();
+
+    /**
+     * This method is called to configure the specific benchmark run
+     * Tasks done in this method include reading user parameters,
+     * logging them and initializing various local variables.
+     *
+     * @throws Exception If configuration was not successful
+     */
+    public void configure() throws Exception {
+        
+        params = getParamRepository();
+
+        //Obtaining configuration parameters
+        String webserverType = params.getParameter("webServer/type");
+ 
+        webServerBinPath = params.getParameter("webServer/hostBinPath");
+        webServerLogPath = params.getParameter("webServer/hostLogPath");
+        webServerConfPath = params.getParameter("webServer/hostConfPath");
+        webServerPidPath = params.getParameter("webServer/hostPidPath");
+        phpIniPath = params.getParameter("webServer/phpIniPath");
+        cacheBinPath = params.getParameter("cacheServers/cacheBinPath");
+        dbConfPath = params.getParameter("dbServer/dbConfPath");
+        String[] dbhosts = params.getParameter(
+                            "dbServer/fa:hostConfig/fa:host").split(" ");
+        String[] webhosts = params.getParameter(
+                            "webServer/fa:hostConfig/fa:host").split(" ");
+
+        if ("apache".equals(webserverType)) {
+            webServerService = ApacheHttpdService.getHandle();
+            for (String webhost : webhosts) {
+                RunContext.getFile(webhost, webServerConfPath +
+                        File.separator + "httpd.conf", RunContext.getOutDir() +
+                        "httpd_conf.log." + getHostName(webhost));
+            }
+        } else if ("lighttpd".equals(webserverType)) {
+            webServerService = LighttpdService.getHandle();
+            for (String webhost : webhosts) {
+                RunContext.getFile(webhost, webServerConfPath +
+                        File.separator + "lighttpd.conf",
+                        RunContext.getOutDir() + "lighttpd_conf.log." +
+                        getHostName(webhost));
+            }
+        } else if ("glassfish".equals(webserverType)) {
+            webServerService = GlassfishService.getHandle();
+            for (String webhost : webhosts) {
+                RunContext.getFile(webhost, webServerConfPath +
+                        File.separator + "domain.xml",
+                        RunContext.getOutDir() + "domain_xml.log." +
+                        getHostName(webhost));
+            }
+        }
+        if (phpIniPath != null && phpIniPath.length() > 0)
+            for (String webhost : webhosts) {
+                RunContext.getFile(webhost, phpIniPath + "/php.ini",
+                        RunContext.getOutDir() + "php_ini.log." +
+                        getHostName(webhost));
+            }
+
+        for (String dbhost : dbhosts) {
+            RunContext.getFile(dbhost, dbConfPath + "/my.cnf",
+            RunContext.getOutDir() + "my_cnf.log." + getHostName(dbhost));
+        }
+
+        // Reloading database and media as necessary.
+        boolean reloadDB = Boolean.parseBoolean(
+                params.getParameter("dbServer/reloadDB"));
+        boolean reloadMedia = Boolean.parseBoolean(
+                params.getParameter("dataStorage/reloadMedia"));
+
+        int scale = -1;
+        if (reloadDB || reloadMedia)
+            scale =Integer.parseInt(params.getParameter("dbServer/scale"));
+
+        CommandHandle dbHandle = null;
+        CommandHandle mediaHandle = null;
+        if (reloadDB) {
+            logger.info("Reloading the database for " + scale + " users!");
+            String dbhost = dbhosts[0];
+            String driver = params.getParameter("dbServer/dbDriver");
+            String connectURL = params.getParameter("dbServer/connectURL");
+            // Un-escape the URL.
+            connectURL = connectURL.replace("&amp;", "&");
+
+            boolean autoCommit = Boolean.parseBoolean(params.getParameter(
+                                                    "dbServer/autoCommit"));
+            ArrayList<String> cmdList = new ArrayList<String>();
+            if (autoCommit)
+                cmdList.add("-Dcommit.tx=false");
+            cmdList.add("com.sun.web20.loader.LoadController");
+            cmdList.add(driver);
+            cmdList.add(connectURL);
+            cmdList.add(String.valueOf(scale));
+            Command c = new Command(cmdList);
+            c.setSynchronous(false);
+            dbHandle = java(dbhost, c);
+        }
+
+        if (reloadMedia) {
+            logger.info("Reloading images/media for " + scale + " users!");
+            String mediaHost = params.getParameter(
+                                        "dataStorage/fa:hostConfig/fa:host");
+            String mediaDir = params.getParameter("dataStorage/mediaDir");
+            Command c = new Command("com.sun.web20.fsloader.FileLoader",
+                        getBenchmarkDir() + "resources", mediaDir,
+                        String.valueOf(scale));
+            c.setSynchronous(false);
+            mediaHandle = java(mediaHost, c);
+        }
+        
+        if (dbHandle != null)
+            dbHandle.waitFor();
+        
+        if (mediaHandle != null)
+            mediaHandle.waitFor();
+        
+        //start the memcache servers
+        memcacheServers =
+                 params.getHostPorts("cacheServers/fa:hostConfig/fa:hostPorts");
+
+         // Assign the default port.
+         for (NameValuePair<Integer> hostPort : memcacheServers) {
+             if (hostPort.value == null)
+                 hostPort.value = 11211;
+         }
+
+        int index = 0;
+        String memServers[] = new String[memcacheServers.size()];
+        int ports[] = new int[memcacheServers.size()];
+        for (NameValuePair<Integer> thisCacheServer : memcacheServers) {
+            memServers[index] = thisCacheServer.name;
+            ports[index++] = thisCacheServer.value;
+        } 
+        memcachedService.setup(memServers, ports, "-u mysql -m 256",
+                cacheBinPath);
+        if ( !memcachedService.restartServers())
+            throw (new Exception("Memcached server(s) restart failed"));
+        
+        // Now start the web servers
+        if (webServerService != null) {
+            webServerService.setup(webhosts, webServerBinPath, webServerLogPath,
+                                    webServerConfPath, webServerPidPath);
+            if (!webServerService.restartServers())
+                throw (new Exception("Webserver(s) restart failed"));
+        }
+
+        //calculate total running time, including rampUp, steadyState,
+        // and rampDown
+        String rampUp = params.getParameter(
+                               "fa:runConfig/fa:runControl/fa:rampUp");
+        String steadyState = params.getParameter(
+                               "fa:runConfig/fa:runControl/fa:steadyState");
+        String rampDown = params.getParameter(
+                               "fa:runConfig/fa:runControl/fa:rampDown");
+
+        this.totalRunningTimeInSecs = Integer.parseInt(rampUp) +
+                Integer.parseInt(steadyState) + Integer.parseInt(rampDown);
+
+        super.configure();
+    }
+
+    /* override DefaultBenchmark's end method to collect webserver log file
+     * via the Web20Benchmark harness class
+     */
+    public void end () throws Exception {
+     
+        super.end();
+        //stop the memcached servers
+        //logger.info("Stopping Memcached servers");
+        //memcachedService.stopServers();
+
+        if (webServerService != null) {
+            // xfer logs
+            logger.info("Transferring webserver error logs");
+            webServerService.xferLogs(totalRunningTimeInSecs);
+
+            // stop web servers
+            logger.info("Stopping web servers");
+            webServerService.stopServers();
+        }
+    }
+
+    /* Override DefaultBenchmark's kill method to stop the servers.
+     */
+    public void kill() throws Exception {
+        memcachedService.stopServers();
+        if (webServerService != null)
+            webServerService.kill();
+        super.kill();
+    }
+}

Propchange: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Address.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Address.java?rev=745169&view=auto
==============================================================================
--- incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Address.java (added)
+++ incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Address.java Tue Feb 17 17:43:25 2009
@@ -0,0 +1,99 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *  
+ * $Id: Address.java,v 1.1.1.1 2008/09/29 22:33:08 sp208304 Exp $
+ */
+package org.apache.olio.workload.loader;
+
+import com.sun.faban.driver.util.Random;
+import org.apache.olio.workload.util.RandomUtil;
+import org.apache.olio.workload.loader.framework.Loadable;
+import org.apache.olio.workload.loader.framework.ThreadConnection;
+import org.apache.olio.workload.loader.framework.ThreadResource;
+
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+
+/**
+ * Address loader.
+ */
+public class Address extends Loadable {
+
+    private static final String STATEMENT = "insert into ADDRESS (street1, " +
+            "street2, city, state, zip, country, latitude, longitude)" +
+            "values (?, ?, ?, ?, ?, ?, ?, ?)";
+    public static final String[] STREETEXTS = { "Blvd", "Ave", "St", "Ln", "" };
+    static Logger logger = Logger.getLogger(Address.class.getName());
+
+    String[] fields = new String[8];
+
+    public String getClearStatement() {
+        return "truncate table ADDRESS";
+    }
+
+    public void prepare() {
+        ThreadResource tr = ThreadResource.getInstance();
+        Random r = tr.getRandom();
+        StringBuilder buffer = tr.getBuffer();
+        buffer.append(r.makeNString(1, 5)).append(' '); // number
+        RandomUtil.randomName(r, buffer, 1, 11); // street
+        String streetExt = STREETEXTS[r.random(0, STREETEXTS.length - 1)];
+        if (streetExt.length() > 0)
+            buffer.append(' ').append(streetExt);
+
+        fields[0] = buffer.toString();
+
+        int toggle = r.random(0, 1); // street2
+        if (toggle > 0)
+            fields[1] = r.makeCString(5, 20);
+
+        fields[2] = r.makeCString(4, 14); // city
+        fields[3] = r.makeCString(2, 2).toUpperCase(); // state
+        fields[4] = r.makeNString(5, 5);  // zip
+
+        toggle = r.random(0, 1);
+        if (toggle == 0) {
+            fields[5] = "USA";
+        } else {
+            buffer.setLength(0);
+            fields[5] = RandomUtil.randomName(r, buffer, 6, 16).toString();
+        }
+        // Latitude, we do not get addresses in polar circles. So the limit
+        fields[6] = String.format("%.6f", r.drandom(-66.560556d, 66.560556d));
+
+        fields[7] = String.format("%.6f", r.drandom(-179.999999d, 180d));
+    }
+
+    public void load() {
+        ThreadConnection c = ThreadConnection.getInstance();
+        try {
+            PreparedStatement s = c.prepareStatement(STATEMENT);
+            for (int i = 0; i < fields.length; i++)
+                if (fields[i] != null)
+                    s.setString(i + 1, fields[i]);
+                else
+                    s.setNull(i + 1, Types.VARCHAR);
+            c.addBatch();
+        } catch (SQLException e) {
+            logger.log(Level.SEVERE, e.getMessage(), e);
+        }
+    }
+}

Added: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Attendees.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Attendees.java?rev=745169&view=auto
==============================================================================
--- incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Attendees.java (added)
+++ incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Attendees.java Tue Feb 17 17:43:25 2009
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * $Id: Attendees.java,v 1.1.1.1 2008/09/29 22:33:08 sp208304 Exp $
+ */
+package org.apache.olio.workload.loader;
+
+import com.sun.faban.driver.util.Random;
+import org.apache.olio.workload.util.ScaleFactors;
+import org.apache.olio.workload.util.UserName;
+import org.apache.olio.workload.loader.framework.Loadable;
+import org.apache.olio.workload.loader.framework.ThreadConnection;
+import org.apache.olio.workload.loader.framework.ThreadResource;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.LinkedHashSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Attendees Loader
+ */
+public class Attendees extends Loadable {
+    // We use on average of 55 attendees per event. Random 10..100 Attendees.
+
+    private static final String STATEMENT = "insert into " +
+            "PERSON_SOCIALEVENT " +
+            "(username, socialeventid) values (?, ?)";
+
+    static Logger logger = Logger.getLogger(Attendees.class.getName());
+
+    int eventId;
+    String[] userNames;
+
+    public String getClearStatement() {
+        return "truncate table PERSON_SOCIALEVENT";
+    }
+
+    public void prepare() {
+        eventId = getSequence();
+        ++eventId;
+        ThreadResource tr = ThreadResource.getInstance();
+        Random r = tr.getRandom();
+        int attendees = r.random(10, 100);
+        LinkedHashSet<Integer> userIdSet = 
+                                    new LinkedHashSet<Integer>(attendees);
+        for (int i = 0; i <attendees; i++)
+            while(!userIdSet.add(r.random(1, ScaleFactors.users)));
+
+        userNames = new String[userIdSet.size()];
+        int idx = 0;
+        for (int userId : userIdSet)
+            userNames[idx++] = UserName.getUserName(userId);
+    }
+
+
+    public void load() {
+        ThreadConnection c = ThreadConnection.getInstance();
+        try {
+            for (String userName : userNames) {
+                PreparedStatement s = c.prepareStatement(STATEMENT);
+                s.setString(1, userName);
+                s.setInt(2, eventId);
+                c.addBatch();
+            }
+        } catch (SQLException e) {
+            logger.log(Level.SEVERE, e.getMessage(), e);
+        }
+    }
+}

Added: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Comments.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Comments.java?rev=745169&view=auto
==============================================================================
--- incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Comments.java (added)
+++ incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Comments.java Tue Feb 17 17:43:25 2009
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * $Id: Comments.java,v 1.1.1.1 2008/09/29 22:33:08 sp208304 Exp $
+ */
+package org.apache.olio.workload.loader;
+
+import com.sun.faban.driver.util.Random;
+import org.apache.olio.workload.util.ScaleFactors;
+import org.apache.olio.workload.util.UserName;
+import org.apache.olio.workload.loader.framework.Loadable;
+import org.apache.olio.workload.loader.framework.ThreadConnection;
+import org.apache.olio.workload.loader.framework.ThreadResource;
+
+import java.sql.Date;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+/**
+ * Comments Loader.
+ */
+public class Comments extends Loadable {
+    // We use on average of 10 comments per event. Random 0..20 comments..
+    public static final Date BASE_DATE = new Date(System.currentTimeMillis());
+    private static final String STATEMENT = "insert into COMMENTS_RATING " +
+            "(username, socialeventid, comments, ratings, created_at) values (?, ?, ?, ?, ?)";
+
+    static Logger logger = Logger.getLogger(Comments.class.getName());
+
+    int eventId;
+    String[] userNames;
+    String[] comments;
+    int[] ratings;
+    Date created_at;
+    
+    public String getClearStatement() {
+        return "truncate table COMMENTS_RATING";
+    }
+
+    public void prepare() {
+        eventId = getSequence();
+        ++eventId;
+        ThreadResource tr = ThreadResource.getInstance();
+        Random r = tr.getRandom();
+        int commentCount = r.random(0, 20);
+        userNames = new String[commentCount];
+        comments = new String[commentCount];
+        ratings = new int[commentCount];
+        for (int i = 0; i < userNames.length; i++) {
+            int userId = r.random(1, ScaleFactors.users);
+            userNames[i] = UserName.getUserName(userId);
+            comments[i] = r.makeCString(10, 1000);
+            ratings[i] = r.random(2, 5);
+        }
+        created_at = r.makeDateInInterval( BASE_DATE, -540, 0);
+    }
+
+
+    public void load() {
+        ThreadConnection c = ThreadConnection.getInstance();
+        try {
+            for (int i = 0; i < userNames.length; i++) {
+                PreparedStatement s = c.prepareStatement(STATEMENT);
+                s.setString(1, userNames[i]);
+                s.setInt(2, eventId);
+                s.setString(3, comments[i]);
+                s.setInt(4, ratings[i]);                
+                s.setDate(5, created_at);
+                c.addBatch();
+            }
+        } catch (SQLException e) {
+            logger.log(Level.SEVERE, e.getMessage(), e);
+        }
+    }
+
+}

Added: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/EventTag.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/EventTag.java?rev=745169&view=auto
==============================================================================
--- incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/EventTag.java (added)
+++ incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/EventTag.java Tue Feb 17 17:43:25 2009
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * $Id: EventTag.java,v 1.1.1.1 2008/09/29 22:33:08 sp208304 Exp $
+ */
+package org.apache.olio.workload.loader;
+
+import com.sun.faban.driver.util.Random;
+import org.apache.olio.workload.util.RandomUtil;
+import org.apache.olio.workload.loader.framework.Loadable;
+import org.apache.olio.workload.loader.framework.ThreadConnection;
+import org.apache.olio.workload.loader.framework.ThreadResource;
+
+import java.util.LinkedHashSet;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The Tag-Event relationship loader.
+ */
+public class EventTag extends Loadable{
+
+    // We use on average of 3.5 tags per event. Random 1..6 tags.
+    // Once we know the tag count, we have to select tags.
+
+    private static final String STATEMENT = "insert into " +
+            "SOCIALEVENTTAG_SOCIALEVENT " +
+            "(socialeventtagid, socialeventid) values (?, ?)";
+
+    static Logger logger = Logger.getLogger(EventTag.class.getName());
+
+    int eventId;
+    int [] tagIds;
+
+    public String getClearStatement() {
+        return "truncate table SOCIALEVENTTAG_SOCIALEVENT";
+    }
+
+    public void prepare() {
+        eventId = getSequence();
+        ++eventId;
+        ThreadResource tr = ThreadResource.getInstance();
+        Random r = tr.getRandom();
+        int numTags = r.random(1, 7); // Avg is 4 tags per event
+        LinkedHashSet<Integer> tagSet = new LinkedHashSet<Integer>(numTags);
+        for (int i = 0; i < numTags; i++)
+            while (!tagSet.add(RandomUtil.randomTagId(r, 0.1d)));
+
+        tagIds = new int[tagSet.size()];
+        int idx = 0;
+        for (int tagId : tagSet)
+            tagIds[idx++] = tagId;
+    }
+
+
+    public void load() {
+        ThreadConnection c = ThreadConnection.getInstance();
+        try {
+            for (int tagId : tagIds) {
+                PreparedStatement s = c.prepareStatement(STATEMENT);
+                s.setInt(1, tagId);
+                s.setInt(2, eventId);
+                c.addBatch();
+            }
+        } catch (SQLException e) {
+            logger.log(Level.SEVERE, e.getMessage(), e);
+        }
+    }
+}

Added: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Friends.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Friends.java?rev=745169&view=auto
==============================================================================
--- incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Friends.java (added)
+++ incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/Friends.java Tue Feb 17 17:43:25 2009
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * $Id: Friends.java,v 1.1.1.1 2008/09/29 22:33:08 sp208304 Exp $
+ */
+package org.apache.olio.workload.loader;
+
+import com.sun.faban.driver.util.Random;
+import org.apache.olio.workload.util.ScaleFactors;
+import org.apache.olio.workload.util.UserName;
+import org.apache.olio.workload.loader.framework.Loadable;
+import org.apache.olio.workload.loader.framework.ThreadConnection;
+import org.apache.olio.workload.loader.framework.ThreadResource;
+
+import java.util.LinkedHashSet;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+/**
+ * Friends loader
+ */
+public class Friends extends Loadable {
+    // We use on average of 15 friends. Random 2..28 Friends.
+
+    private static final String STATEMENT = "insert into PERSON_PERSON " +
+            "(Person_username, friends_username,is_accepted) values (?, ?, ?)";
+
+    static Logger logger = Logger.getLogger(Friends.class.getName());
+
+    String userName;
+    String[] friends;
+
+    public String getClearStatement() {
+        return "truncate table PERSON_PERSON";
+    }
+
+    public void prepare() {
+        int id = getSequence();
+        ++id;
+        ThreadResource tr = ThreadResource.getInstance();
+        Random r = tr.getRandom();
+        userName = UserName.getUserName(id);
+        int count = r.random(2, 28);
+
+        LinkedHashSet<Integer> friendSet = new LinkedHashSet<Integer>(count);
+        for (int i = 0; i < count; i++) {
+            int friendId;
+            do { // Prevent friend to be the same user.
+                friendId = r.random(1, ScaleFactors.users);
+            } while (friendId == id || !friendSet.add(friendId));
+        }
+
+        friends = new String[friendSet.size()];
+        int idx = 0;
+        for (int friendId : friendSet)
+            friends[idx++] = UserName.getUserName(friendId);
+    }
+
+    public void load() {
+        ThreadConnection c = ThreadConnection.getInstance();
+        try {
+            int alternate = 0;
+            for (String friend : friends) {
+                PreparedStatement s = c.prepareStatement(STATEMENT);
+                s.setString(1, userName);
+                s.setString(2, friend);
+                if (alternate%2 == 0){
+                    s.setInt(3, 0);
+                }else{
+                    s.setInt(3, 1);
+                }
+                alternate++;
+                c.addBatch();
+            }
+        } catch (SQLException e) {
+            logger.log(Level.SEVERE, e.getMessage(), e);
+        }
+    }
+}

Added: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/LoadController.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/LoadController.java?rev=745169&view=auto
==============================================================================
--- incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/LoadController.java (added)
+++ incubator/olio/workload/php/trunk/src/org/apache/olio/workload/loader/LoadController.java Tue Feb 17 17:43:25 2009
@@ -0,0 +1,76 @@
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * $Id: LoadController.java,v 1.1.1.1 2008/09/29 22:33:08 sp208304 Exp $
+ */
+package org.apache.olio.workload.loader;
+
+import org.apache.olio.workload.util.ScaleFactors;
+
+import java.util.logging.Logger;
+
+import static org.apache.olio.workload.loader.framework.Loader.*;
+
+public class LoadController {
+
+    static Logger logger = Logger.getLogger(LoadController.class.getName());
+
+    public static void main(String[] args) throws Exception {
+        setJDBCDriverClassName(args[0]);
+        setConnectionURL(args[1]);
+        ScaleFactors.setActiveUsers(Integer.parseInt(args[2]));
+
+        // Clear the database
+        clear(Person.class);
+        clear(Friends.class);
+        clear(Address.class);
+        clear(Tag.class);
+        clear(SocialEvent.class);
+        clear(EventTag.class);
+        clear(Attendees.class);
+        clear(Comments.class);
+        logger.info("Done clearing database tables.");
+
+        // load person, friends, and addresses
+        load(Person.class, ScaleFactors.users);
+        load(Friends.class, ScaleFactors.users);
+        load(Address.class, ScaleFactors.users);
+
+        // load tags
+        load(Tag.class, ScaleFactors.tagCount);
+
+        // load events and all relationships to events
+        load(SocialEvent.class, ScaleFactors.events);
+        load(EventTag.class, ScaleFactors.events);
+        load(Attendees.class, ScaleFactors.events);
+        load(Comments.class, ScaleFactors.events);
+
+        waitProcessing();
+        logger.info("Done data creation.");
+
+        // Now we need to check that all loading is done.
+        shutdown();
+        logger.info("Done data loading.");
+
+        // We use a new set of connections and thread pools for postLoad.
+        // This is to ensure all load tasks are done before this one starts.
+        postLoad(Tag.class);
+        shutdown();
+        logger.info("Done post-load.");
+        System.exit(0); // Signal successful loading.
+    }
+}



Mime
View raw message