Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the Entrypoint of Web Search #404

Merged
merged 6 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions benchmarks/web-search/client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ ENV SCALE 50
ENV AGENT_ID 1
ENV NUM_AGENTS 1

# The entrypoint is a Python script
RUN apt update && apt install python3 -y

RUN cd $BASE_PATH \
&& wget "archive.apache.org/dist/ant/binaries/apache-ant-$ANT_VERSION-bin.tar.gz" \
&& tar -zxf apache-ant-$ANT_VERSION-bin.tar.gz \
Expand All @@ -28,11 +31,14 @@ COPY files $FABAN_HOME/.
RUN cd $FABAN_HOME/search \
&& sed -i "/faban.home/c\\faban.home=$FABAN_HOME" build.properties \
&& sed -i "/ant.home/c\\ant.home=$ANT_HOME" build.properties \
&& sed -i "/faban.url/c\\faban.url=http://localhost:$FABAN_PORT/" build.properties
&& sed -i "/faban.url/c\\faban.url=http://localhost:$FABAN_PORT/" build.properties \
&& mkdir -p $FABAN_HOME/search/deploy


COPY docker-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
#COPY docker-entrypoint.sh /entrypoint.sh
COPY docker-entrypoint.py /docker-entrypoint.py
RUN chmod +x /docker-entrypoint.py

EXPOSE $FABAN_PORT

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/docker-entrypoint.py"]
161 changes: 161 additions & 0 deletions benchmarks/web-search/client/docker-entrypoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#!/usr/bin/env python3

import argparse

arg = argparse.ArgumentParser();

arg.add_argument("--ramp-up", type=int, help="The time for ramp up, in seconds", default=20)
arg.add_argument("--ramp-down", type=int, help="The time for ramp down, in seconds", default=10)
arg.add_argument("--steady", type=int, help="The time for measurement, in seconds", default=60)

arg.add_argument("--interval-min", type=int, help="The minimum interval for request generation, in milliseconds", default=1000)
arg.add_argument("--interval-max", type=int, help="The maximum interval for request generation, in milliseconds", default=1500)
arg.add_argument("--interval-deviation", type=float, help="The deviation of the interval, in percentage.", default=0)
arg.add_argument("--interval-type", choices=["ThinkTime", "CycleTime"], help="The interval type.", default="ThinkTime")
arg.add_argument("--interval-distribution", choices=["Fixed", "Uniform", "NegativeExponential"], help="The distribution of interval", default="Fixed")

arg.add_argument("--dataset-distribution", choices=["Random", "Zipfian"], help="The distribution of the request", default="Zipfian")
arg.add_argument("--output-query-result", "-q", action="store_true", help="Whether let Faban output search query. Can be a potential performance bottleneck.")

arg.add_argument("server_ip", help="The IP address of the server")
arg.add_argument("worker_count", help="The number of workers to generate requests")

arg = arg.parse_args()


# Load template
import os
FABAN_HOME = os.environ["FABAN_HOME"]

TEMPLATES: dict[str, str] = {}
HEADER: str = ""

with open(f"{FABAN_HOME}/search/template/head.java.in") as f:
HEADER = f.read()

for dist in ["Random", "Zipfian"]:
with open(f"{FABAN_HOME}/search/template/{dist}.java.in") as f:
TEMPLATES[dist] = f.read()

# Generate SearchDriver.java
with open(f"{FABAN_HOME}/search/src/sample/searchdriver/SearchDriver.java", "x") as f:
f.write("// this file is automatically generated by docker-entrypoint.py. DO NOT MODIFY. \n")
f.write(HEADER)
# Base on the interval type, start writing stuff.
f.write("\n");

if arg.interval_distribution == "Fixed":
f.write("@FixedTime(cycleTime = {}, cycleType = CycleType.{}, cycleDeviation={})\n".format(
arg.interval_min,
arg.interval_type.upper(),
arg.interval_deviation
))
if arg.interval_min != arg.interval_max:
print("Warning: the maximal interval should be same as the minimal interval when fixed distribution is used. The program uses minimal interval as the fixed interval.")
elif arg.interval_distribution == "Uniform":
f.write("@Uniform(cycleMin = {}, cycleMax = {}, cycleType = CycleType.{}, cycleDeviation = {})\n".format(
arg.interval_min,
arg.interval_max,
arg.interval_type.upper(),
arg.interval_deviation
))
elif arg.interval_distribution == "NegativeExponential":
f.write("@NegativeExponential(cycleMin = {}, cycleMax = {}, cycleMean = {}, cycleType = CycleType.{}, cycleDeviation = {})\n".format(
arg.interval_min,
arg.interval_max,
int((arg.interval_min * arg.interval_max) ** 0.5),
arg.interval_type.upper(),
arg.interval_deviation
))

# Now write the load generator.
assert arg.dataset_distribution in TEMPLATES

content = TEMPLATES[arg.dataset_distribution]

if arg.output_query_result:
content = content.replace("System.out.println(sb.toString());", "")

f.write(content)


import socket
import shutil

# Generate run.xml

RUN_XML_TEMPLATE: str = ""
with open(f"{FABAN_HOME}/search/template/run.xml.in") as f:
RUN_XML_TEMPLATE = f.read()

with open(f"{FABAN_HOME}/search/deploy/run.xml", "w") as f:
f.write(RUN_XML_TEMPLATE.format(
SCALE = arg.worker_count,
RAMP_UP_TIME = arg.ramp_up,
RAMP_DOWN_TIME = arg.ramp_down,
STEADY_TIME = arg.steady,
FABAN_OUTPUT_DIR = os.environ["FABAN_OUTPUT_DIR"],
AGENTS = "{}:{}".format(
socket.gethostname(),
os.environ["NUM_AGENTS"]
),
SERVER_IP = arg.server_ip,
PORT_NUMBER = os.environ["SOLR_PORT"],
TERM_FILE = "{}/search/src/sample/searchdriver/{}".format(
FABAN_HOME,
"terms_ordered" if arg.dataset_distribution == "Zipfian" else "terms_random"
)
))

# Setup the environment
os.environ["JAVA_HOME"] = os.path.dirname(os.path.dirname(os.path.realpath(shutil.which("javac"))))
os.environ["SOLR_JAVA_HOME"] = os.environ["JAVA_HOME"]

print(os.environ["JAVA_HOME"])

# Setup Faban
os.system(f"{FABAN_HOME}/master/bin/startup.sh")

# Update the build.properties with JDK 11.
os.system(f"sed -i 's/^compiler.target.version=.*/compiler.target.version=11/' {FABAN_HOME}/search/build.properties")

# Start building
os.chdir(f"{FABAN_HOME}/search")
os.system(f"{os.environ['ANT_HOME']}/bin/ant deploy")

CLASS_PATH = f"{FABAN_HOME}/lib/fabanagents.jar:{FABAN_HOME}/lib/fabancommon.jar:{FABAN_HOME}/lib/fabandriver.jar:{os.environ['JAVA_HOME']}/lib/tools.jar:{FABAN_HOME}/search/build/lib/search.jar"

os.environ["CLASSPATH"] = CLASS_PATH

import http.client
import time

con = http.client.HTTPConnection(arg.server_ip, os.environ["SOLR_PORT"])
while True:
willConnect = True
try:
con.connect()
except:
willConnect = False
print("-")

if willConnect:
# It is connected.
con.close()
break
time.sleep(5)

# Register
os.system(f"java -classpath {CLASS_PATH} -Djava.security.policy={os.environ['POLICY_PATH']} com.sun.faban.common.RegistryImpl &")
time.sleep(3)

# Start Agent
os.system(f"java -classpath {CLASS_PATH} -Xmx{os.environ['CLIENT_HEAP_SIZE']} -Xms{os.environ['CLIENT_HEAP_SIZE']} -Djava.security.policy={os.environ['POLICY_PATH']} com.sun.faban.driver.engine.AgentImpl 'SearchDriver' {os.environ['AGENT_ID']} {socket.gethostname()} &")

# Start Master
os.system(f"java -classpath {CLASS_PATH} -Xmx{os.environ['CLIENT_HEAP_SIZE']} -Xms{os.environ['CLIENT_HEAP_SIZE']} -Djava.security.policy={os.environ['POLICY_PATH']} -Dbenchmark.config={os.environ['BENCHMARK_CONFIG']} com.sun.faban.driver.engine.MasterImpl")

time.sleep(4)

os.system(f"cat {os.environ['FABAN_OUTPUT_DIR']}/1/summary.xml")

73 changes: 0 additions & 73 deletions benchmarks/web-search/client/docker-entrypoint.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,72 +1,3 @@
/* CloudSuite4.0 Benchmark Suite
* Copyright (c) 2022, Parallel Systems Architecture Lab, EPFL
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.

* - Neither the name of the Parallel Systems Architecture Laboratory,
* EPFL nor the names of its contributors may be used to endorse or
* promote products derived from this software without specific prior
* written permission.

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* PARALLEL SYSTEMS ARCHITECTURE LABORATORY, EPFL BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Author: Stavros Volos, Vukasin Stefanovic
*/

package sample.searchdriver;

import com.sun.faban.driver.*;
import javax.xml.xpath.XPathExpressionException;
import java.io.*;
import java.util.Vector;
import java.util.logging.Logger;
import java.util.Random;

@BenchmarkDefinition(
name = "Sample Search Workload",
version = "0.4",
configPrecedence = true
)
@BenchmarkDriver(
name = "SearchDriver",
threadPerScale = 1
)
@FlatMix(
operations = {
"GET"
},
mix = {
100
},
deviation = 0
)
@NegativeExponential(
cycleType = CycleType.CYCLETIME,
cycleMean = 2000,
cycleDeviation = 2
)

public class SearchDriver {
private DriverContext ctx;
private HttpTransport http;
Expand Down Expand Up @@ -184,13 +115,12 @@ public void doGet() throws IOException {
}
query = query + s;
}
// Create the http request
url = frontend + "/solr/cloudsuite_web_search/query?q=" + query + "&lang=en&fl=url&df=text&rows=10&q.op=AND";
url = frontend + "/solr/cloudsuite_web_search/query?q=" + query + "&lang=en&fl=url&df=text&rows=10&q.op=OR";
try {
StringBuilder sb = http.fetchURL(url);
System.out.println(sb.toString());
} catch (IOException e) {
logger.severe("ERROR!!!!!!!!!!!!!!!\n");
logger.severe("ERROR!\n");
}
}
}
Loading