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

Modified Logic to change sql criteria based on configuration #10

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (C) 2014-2016 LinkedIn Corp. (pinot-core@linkedin.com)
*
* Licensed 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.
*/

package com.linkedin.pinot.tools.pacelab.benchmark;

public class Constant {

public static final String GROUP_BY_LIMIT = "GroupByLimit";
public static final String VIEW_START_TIME = "ViewStartTime";
public static final String ZIPFS_PARAMETER = "ZipfSParameter";
public static final String QUERY_TYPE = "queryType";
shsahu marked this conversation as resolved.
Show resolved Hide resolved
public static final String MIN_PROFILE_START_TIME = "MinProfileViewStartTime";
public static final String MAX_PROFILE_START_TIME = "MaxProfileViewStartTime";
public static final String QPS = "QPS";



public static final int HOURSECOND = 3600;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* Copyright (C) 2014-2016 LinkedIn Corp. (pinot-core@linkedin.com)
*
* Licensed 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.
*/
package com.linkedin.pinot.tools.pacelab.benchmark;

import java.util.Properties;

import org.apache.commons.lang.math.LongRange;
import org.xerial.util.ZipfRandom;

public class Criteria
{
private Long maxApplyStartTime;
shsahu marked this conversation as resolved.
Show resolved Hide resolved
private Long minApplyStartTime;
private int queryType;
private int secsInDuration;
private ZipfRandom zipfRandom;

public Criteria(Properties config, String maxStartTime, String minStartTime) {
minApplyStartTime = Long.parseLong(config.getProperty(minStartTime));
maxApplyStartTime = Long.parseLong(config.getProperty(maxStartTime));
queryType = Integer.parseInt(config.getProperty(Constant.QUERY_TYPE));
secsInDuration = Constant.HOURSECOND;
switch(queryType) {
case 2 : secsInDuration *= 7;
shsahu marked this conversation as resolved.
Show resolved Hide resolved
case 1 : secsInDuration *= 24;
}
double zipfS = Double.parseDouble(config.getProperty(Constant.ZIPFS_PARAMETER));
int count = (int) Math.ceil((maxApplyStartTime-minApplyStartTime)/(secsInDuration));
zipfRandom = new ZipfRandom(zipfS,count);
}

private LongRange getTimeRange() {
int duration = zipfRandom.nextInt();
long queriedEndTime = maxApplyStartTime;
long queriedStartTime = Math.max(minApplyStartTime,queriedEndTime - duration*secsInDuration);
LongRange timeRange = new LongRange(queriedStartTime,queriedEndTime);
return timeRange;
}
public String getClause(String column) {
LongRange timeRange = getTimeRange();
if (queryType == 0)
return "";
return " AND " + column + " > " + timeRange.getMinimumLong() +" AND " + column + " < "+timeRange.getMaximumLong();
shsahu marked this conversation as resolved.
Show resolved Hide resolved

}
}


//public abstract class Criteria {
//
// abstract protected Long maxApplyStartTime();
// abstract protected Long minApplyStartTime();
// abstract protected int queryType();
// abstract protected int durationSecs();
// abstract protected ZipfRandom zipfRandom();
//
// protected String param() {
// return null;
// }
//
// LongRange getTimeRange() {
// long queriedEndTime = maxApplyStartTime() - zipfRandom().nextInt()*durationSecs();
// long queriedStartTime = minApplyStartTime();
// LongRange timeRange = new LongRange(queriedStartTime,queriedEndTime);
// return timeRange;
// }
// String getClause() {
// LongRange timeRange = getTimeRange();
// if (queryType() == 0)
// return "";
// return " AND " + param() + " > " + timeRange.getMinimumLong() +" AND " + timeRange.getMaximumLong() + " < %d ";
//
// }
//
//
//}
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,28 @@ private static String[] getQueries() {
" WHERE ViewStartTime > %d AND ViewStartTime < %d",
"SELECT * FROM ProfileView" +
" WHERE ViewStartTime > %d AND ViewStartTime < %d AND ViewedProfileId = '%s' LIMIT %d",*/
"SELECT COUNT(*), AVG(ReviewTime), AVG(ViewerProfileStrength) FROM ProfileView" +
// " WHERE ViewStartTime > %d AND ViewStartTime < %d AND ViewedProfileId = '%s'",
" WHERE ViewedProfileId = '%s'",
"SELECT ViewerPosition, COUNT(*) FROM ProfileView" +
//" WHERE ViewStartTime > %d AND ViewStartTime < %d AND ViewedProfileId = '%s'"+
" WHERE ViewedProfileId = '%s'"+
" GROUP BY ViewerPosition TOP %d",
"SELECT ViewerWorkPlace, COUNT(*) FROM ProfileView" +
// " WHERE ViewStartTime > %d AND ViewStartTime < %d AND ViewedProfileId = '%s'"+
" WHERE ViewedProfileId = '%s'"+
" GROUP BY ViewerWorkPlace TOP %d",
"SELECT COUNT(*), AVG(ReviewTime), AVG(ViewerProfileStrength) FROM ProfileView" +
" WHERE ViewedProfilePosition = '%s'",
"SELECT COUNT(*), AVG(ReviewTime), AVG(ViewerProfileStrength) FROM ProfileView " +
" WHERE ViewedProfileWorkPlace = '%s'"
"SELECT COUNT(*), AVG(ReviewTime), AVG(ViewerProfileStrength) FROM ProfileView" +
" WHERE ViewedProfileId = '%s'"+
" %s",


"SELECT ViewerPosition, COUNT(*) FROM ProfileView" +
" WHERE ViewedProfileId = '%s'"+
" %s"+
" GROUP BY ViewerPosition TOP %d",

"SELECT ViewerWorkPlace, COUNT(*) FROM ProfileView" +
" WHERE ViewedProfileId = '%s'"+
" %s"+
" GROUP BY ViewerWorkPlace TOP %d",

"SELECT COUNT(*), AVG(ReviewTime), AVG(ViewerProfileStrength) FROM ProfileView" +
" WHERE ViewedProfilePosition = '%s'"+
" %s",

"SELECT COUNT(*), AVG(ReviewTime), AVG(ViewerProfileStrength) FROM ProfileView " +
" WHERE ViewedProfileWorkPlace = '%s'"+
" %s"
/*
"SELECT ViewedProfilePosition, COUNT(*), AVG(ReviewTime) FROM ProfileView" +
// " WHERE ViewStartTime > %d AND ViewStartTime < %d" +
Expand Down Expand Up @@ -87,6 +94,6 @@ public static ProfileViewQueryExecutor getInstance() {
}

public ProfileViewQueryTask getTask(Properties config) {
return new ProfileViewQueryTask(config, QUERIES, _dataDir, _testDuration);
return new ProfileViewQueryTask(config, QUERIES, _dataDir, _testDuration, getCriteria(Constant.MAX_PROFILE_START_TIME,Constant.MIN_PROFILE_START_TIME));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@

public class ProfileViewQueryTask extends QueryTaskDaemon {
List<GenericRow> _profileTable;

ZipfRandom _zipfRandom;
final static int HourSecond = 3600;
//ZipfRandom _zipfRandom;

Random _profileIndexGenerator;



public ProfileViewQueryTask(Properties config, String[] queries, String dataDir, int testDuration) {
public ProfileViewQueryTask(Properties config, String[] queries, String dataDir, int testDuration, Criteria p_criteria) {
setConfig(config);
setQueries(queries);
setDataDir(dataDir);
setTestDuration(testDuration);
EventTableGenerator eventTableGenerator = new EventTableGenerator(_dataDir);
criteria = p_criteria;

long minProfileViewStartTime = Long.parseLong(config.getProperty("MinProfileViewStartTime"));
long maxProfileViewStartTime = Long.parseLong(config.getProperty("MaxProfileViewStartTime"));
double zipfS = Double.parseDouble(config.getProperty("ZipfSParameter"));

int hourCount = (int) Math.ceil((maxProfileViewStartTime-minProfileViewStartTime)/(HourSecond));
_zipfRandom = new ZipfRandom(zipfS,hourCount);

// long minProfileViewStartTime = Long.parseLong(config.getProperty("MinProfileViewStartTime"));
// long maxProfileViewStartTime = Long.parseLong(config.getProperty("MaxProfileViewStartTime"));
// double zipfS = Double.parseDouble(config.getProperty("ZipfSParameter"));
// int hourCount = (int) Math.ceil((maxProfileViewStartTime-minProfileViewStartTime)/(HourSecond));
// _zipfRandom = new ZipfRandom(zipfS,hourCount);
_profileIndexGenerator = new Random(System.currentTimeMillis());

try
Expand All @@ -68,33 +69,51 @@ public void generateAndRunQuery(int queryId) throws Exception {
EventTableGenerator eventTableGenerator = new EventTableGenerator(_dataDir);
Properties config = getConfig();
String[] queries = getQueries();


long minProfileViewStartTime = Long.parseLong(config.getProperty("MinProfileViewStartTime"));
long maxProfileViewStartTime = Long.parseLong(config.getProperty("MaxProfileViewStartTime"));
//long minProfileViewStartTime = Long.parseLong(config.getProperty("MinProfileViewStartTime"));
//long maxProfileViewStartTime = Long.parseLong(config.getProperty("MaxProfileViewStartTime"));

/*
double zipfS = Double.parseDouble(config.getProperty("ZipfSParameter"));
//LongRange timeRange = CommonTools.getZipfRandomDailyTimeRange(minProfileViewStartTime,maxProfileViewStartTime,zipfS);
LongRange timeRange = CommonTools.getZipfRandomHourlyTimeRange(minProfileViewStartTime,maxProfileViewStartTime,zipfS);
*/

int firstHour = _zipfRandom.nextInt();
//int firstHour = _zipfRandom.nextInt();
//int secondHour = _zipfRandom.nextInt();

// long queriedEndTime = maxProfileViewStartTime;
// long queriedStartTime = Math.max(minProfileViewStartTime,queriedEndTime - firstHour*HourSecond);
// LongRange timeRange = new LongRange(queriedStartTime,queriedEndTime);
//long queriedEndTime = maxApplyStartTime - firstHour*HourSecond;
long queriedEndTime = maxProfileViewStartTime;
long queriedStartTime = Math.max(minProfileViewStartTime,queriedEndTime - firstHour*HourSecond);

LongRange timeRange = new LongRange(queriedStartTime,queriedEndTime);
//long queriedEndTime = maxProfileViewStartTime;
//long queriedStartTime = minProfileViewStartTime;


// if(Integer.parseInt(queryType))
// switch(Integer.parseInt(queryType)) {
// case 1:
// break;
// case 2: queriedEndTime = maxProfileViewStartTime;
// queriedStartTime = Math.max(minProfileViewStartTime,queriedEndTime - firstHour*HourSecond*24);
// //queriedEndTime = maxProfileViewStartTime - firstHour*HourSecond*24;
// //queriedStartTime = queriedEndTime - HourSecond*24;
// break;
// case 3: queriedEndTime = maxProfileViewStartTime;
// queriedStartTime = Math.max(minProfileViewStartTime,queriedEndTime - firstHour*HourSecond*24*7);
// break;
// }

//LongRange timeRange = new LongRange(queriedStartTime,queriedEndTime);

int selectLimit = CommonTools.getSelectLimt(config);
int groupByLimit = Integer.parseInt(config.getProperty("GroupByLimit"));


int groupByLimit = Integer.parseInt(config.getProperty(Constant.GROUP_BY_LIMIT));

GenericRow randomProfile = eventTableGenerator.getRandomGenericRow(_profileTable, _profileIndexGenerator);

String query = "";
String clause = criteria.getClause(Constant.VIEW_START_TIME);
switch (queryId) {
/*
case 0:
Expand All @@ -105,28 +124,28 @@ public void generateAndRunQuery(int queryId) throws Exception {
query = String.format(queries[queryId], timeRange.getMinimumLong(), timeRange.getMaximumLong(), randomProfile.getValue("ID"), selectLimit);
runQuery(query);
break;
*/
case 0:
query = String.format(queries[queryId], randomProfile.getValue("ID"));
runQuery(query);
break;

case 1:
query = String.format(queries[queryId], randomProfile.getValue("ID"), groupByLimit);
runQuery(query);
break;
case 2:
query = String.format(queries[queryId], randomProfile.getValue("ID"), groupByLimit);
runQuery(query);
break;
*/
case 0:
query = String.format(queries[queryId], randomProfile.getValue("ID"),clause);
runQuery(query);
break;
case 1:
query = String.format(queries[queryId], randomProfile.getValue("ID"), clause, groupByLimit);
runQuery(query);
break;
case 2:
query = String.format(queries[queryId], randomProfile.getValue("ID"), clause, groupByLimit);
runQuery(query);
break;
case 3:
query = String.format(queries[queryId], randomProfile.getValue("Position"));
runQuery(query);
break;
query = String.format(queries[queryId], randomProfile.getValue("Position"), clause);
runQuery(query);
break;
case 4:
query = String.format(queries[queryId], randomProfile.getValue("WorkPlace"));
runQuery(query);
break;
query = String.format(queries[queryId], randomProfile.getValue("WorkPlace"), clause);
runQuery(query);
break;
/*
case 5:
query = String.format(queries[queryId], timeRange.getMinimumLong(), timeRange.getMaximumLong(), groupByLimit);
Expand All @@ -146,7 +165,7 @@ public void generateAndRunQuery(int queryId) throws Exception {
query = String.format(queries[queryId], timeRange.getMinimumLong(), timeRange.getMaximumLong(), groupByLimit);
runQuery(query);
break;*/
}
}

}
}
}
Loading