├── .directory
├── .gitignore
├── .travis.yml
├── BUILD
├── LICENSE.txt
├── NOTICE.txt
├── README.md
├── _config.yml
├── adding_a_database.md
├── akumuli
├── akumuli-binding.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ ├── AkumuliClient.java
│ └── Test.java
├── atsd
├── atsd-binding.iml
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── yahoo
│ │ └── ycsb
│ │ └── db
│ │ └── ATSDClient.java
│ └── resources
│ └── logback.xml
├── bin
└── ycsb
├── binding-parent
├── binding-parent.iml
├── datastore-specific-descriptor
│ ├── datastore-specific-descriptor.iml
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── resources
│ │ └── assemblies
│ │ └── datastore-specific-assembly.xml
└── pom.xml
├── blueflood
├── blueflood-binding.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ └── BluefloodClient.java
├── checkstyle.xml
├── core
├── CHANGES.md
├── core.iml
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── yahoo
│ │ └── ycsb
│ │ ├── BasicDB.java
│ │ ├── ByteArrayByteIterator.java
│ │ ├── ByteIterator.java
│ │ ├── Client.java
│ │ ├── CommandLine.java
│ │ ├── DB.java
│ │ ├── DBException.java
│ │ ├── DBFactory.java
│ │ ├── DBWrapper.java
│ │ ├── GoodBadUglyDB.java
│ │ ├── InputStreamByteIterator.java
│ │ ├── RandomByteIterator.java
│ │ ├── StringByteIterator.java
│ │ ├── TerminatorThread.java
│ │ ├── ThreadedCSVReader.java
│ │ ├── UnknownDBException.java
│ │ ├── Utils.java
│ │ ├── Workload.java
│ │ ├── WorkloadException.java
│ │ ├── generator
│ │ ├── AcknowledgedCounterGenerator.java
│ │ ├── ConstantLongGenerator.java
│ │ ├── CounterGenerator.java
│ │ ├── DiscreteGenerator.java
│ │ ├── ExponentialGenerator.java
│ │ ├── FileGenerator.java
│ │ ├── Generator.java
│ │ ├── HistogramGenerator.java
│ │ ├── HotspotLongGenerator.java
│ │ ├── IntegerGenerator.java
│ │ ├── LongGenerator.java
│ │ ├── ScrambledZipfianGenerator.java
│ │ ├── SkewedLatestGenerator.java
│ │ ├── UniformGenerator.java
│ │ ├── UniformLongGenerator.java
│ │ └── ZipfianGenerator.java
│ │ ├── measurements
│ │ ├── Measurements.java
│ │ ├── OneMeasurement.java
│ │ ├── OneMeasurementHdrHistogram.java
│ │ ├── OneMeasurementHistogram.java
│ │ ├── OneMeasurementTimeSeries.java
│ │ ├── TwoInOneMeasurement.java
│ │ └── exporter
│ │ │ ├── JSONArrayMeasurementsExporter.java
│ │ │ ├── JSONMeasurementsExporter.java
│ │ │ ├── MeasurementsExporter.java
│ │ │ └── TextMeasurementsExporter.java
│ │ └── workloads
│ │ ├── ConstantOccupancyWorkload.java
│ │ └── CoreWorkload.java
│ └── test
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ ├── TestByteIterator.java
│ ├── generator
│ ├── AcknowledgedCounterGeneratorTest.java
│ └── TestZipfianGenerator.java
│ └── measurements
│ └── exporter
│ └── TestMeasurementsExporter.java
├── databus
├── databus-binding.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ ├── DatabusClient.java
│ └── Test.java
├── distribution
├── pom.xml
├── src
│ └── main
│ │ └── assembly
│ │ └── distribution.xml
└── ycsb.iml
├── druid
├── druid-binding.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ └── DruidClient.java
├── elasticsearch
├── elasticsearch-binding.iml
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── yahoo
│ │ └── ycsb
│ │ └── db
│ │ ├── ElasticsearchClient.java
│ │ └── Test.java
│ └── resources
│ └── template.json
├── gnocchi
├── gnocchi-binding.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ └── GnocchiClient.java
├── graphite
├── graphite-binding.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ ├── GraphiteClient.java
│ └── Test.java
├── h5serv
├── h5serv-binding.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ ├── H5ServClient.java
│ └── HttpGetWithEntity.java
├── hana
├── hana-binding.iml
├── pom.xml
└── src
│ └── main
│ ├── conf
│ └── hana.properties
│ ├── java
│ └── com
│ │ └── yahoo
│ │ └── ycsb
│ │ └── db
│ │ ├── JdbcDBCli.java
│ │ ├── JdbcDBClient.java
│ │ ├── JdbcDBClientConstants.java
│ │ └── JdbcDBCreateTable.java
│ └── resources
│ └── sql
│ ├── README
│ ├── create_table.monetdb
│ ├── create_table.mysql
│ ├── create_table.psql
│ └── create_table.sql
├── influxdb-java
├── CHANGELOG.md
├── Dockerfile
├── LICENSE
├── influxdb-java.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── influxdb
│ ├── InfluxDB.java
│ ├── InfluxDBFactory.java
│ ├── dto
│ ├── BatchPoints.java
│ ├── Point.java
│ ├── Pong.java
│ ├── Query.java
│ └── QueryResult.java
│ └── impl
│ ├── BatchProcessor.java
│ ├── InfluxDBErrorHandler.java
│ ├── InfluxDBImpl.java
│ ├── InfluxDBService.java
│ └── TimeUtil.java
├── influxdb
├── influxdb-binding.iml
├── influxdb.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ └── InfluxDBClient.java
├── jdbc
├── jdbc-binding.iml
├── pom.xml
└── src
│ └── main
│ ├── conf
│ ├── db.properties
│ └── h2.properties
│ ├── java
│ └── com
│ │ └── yahoo
│ │ └── ycsb
│ │ └── db
│ │ ├── JdbcDBCli.java
│ │ ├── JdbcDBClient.java
│ │ ├── JdbcDBClientConstants.java
│ │ └── JdbcDBCreateTable.java
│ └── resources
│ └── sql
│ ├── README
│ ├── create_table.monetdb
│ ├── create_table.mysql
│ ├── create_table.psql
│ └── create_table.sql
├── kairosdb
├── kairosdb-binding.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ ├── .directory
│ └── ycsb
│ └── db
│ └── KairosDBClient.java
├── kdbplus-java
├── kdbplus-java.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── kx
│ └── c.java
├── kdbplus
├── kdbplus-binding.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ └── KdbPlusClient.java
├── newts
├── newts-binding.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ └── NewTSClient.java
├── opentsdb
├── opentsdb-binding.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ └── OpenTSDBClient.java
├── pom.xml
├── prometheus
├── pom.xml
├── prometheus-binding.iml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ └── PrometheusClient.java
├── rhombus
├── pom.xml
├── rhombus-binding.iml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ └── RhombusClient.java
├── root.iml
├── seriesly
├── pom.xml
├── seriesly-binding.iml
└── src
│ └── main
│ └── java
│ └── com
│ └── yahoo
│ └── ycsb
│ └── db
│ ├── SerieslyClient.java
│ └── Test.java
└── workloads
├── testworkloada
├── testworkloadb
├── workload_template
├── workloada
└── workloadb
/.directory:
--------------------------------------------------------------------------------
1 | [Dolphin]
2 | PreviewsShown=true
3 | Timestamp=2015,11,10,22,3,24
4 | Version=3
5 | ViewMode=1
6 |
7 | [Settings]
8 | HiddenFilesShown=true
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Git ignore File
2 |
3 | **/*.pyc
4 | **/__pycache__
5 | .*
6 | !/.gitignore
7 |
8 | **/*.directory
9 | */data.csv
10 | *.log
11 | *.ydc
12 | *.html
13 | *.pdf
14 | *.tar.gz
15 | **/target/*
16 | .idea/*
17 | # *.iml
18 | .project
19 | .classpath
20 | .settings
21 | .checkstyle
22 | .DS_Store
23 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2010 Yahoo! Inc., 2012 - 2015 YCSB contributors.
2 | # All rights reserved.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License"); you
5 | # may not use this file except in compliance with the License. You
6 | # may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | # implied. See the License for the specific language governing
14 | # permissions and limitations under the License. See accompanying
15 | # LICENSE file.
16 |
17 | # more info here about TravisCI and Java projects
18 | # http://docs.travis-ci.com/user/languages/java/
19 |
20 | language: java
21 |
22 | jdk:
23 | - oraclejdk8
24 | - openjdk8
25 |
26 | install: mvn install -q -DskipTests=true
27 |
28 | script: mvn test -q
29 |
30 | # Use the Container based infrastructure.
31 | sudo: false
32 |
--------------------------------------------------------------------------------
/BUILD:
--------------------------------------------------------------------------------
1 | # Building YCSB
2 |
3 | To build YCSB, run:
4 |
5 | mvn clean package
6 |
7 | # Running YCSB
8 |
9 | Once `mvn clean package` succeeds, you can run `ycsb` command:
10 |
11 | ./bin/ycsb load basic workloads/workloada
12 | ./bin/ycsb run basic workloads/workloada
13 |
14 | # Oracle NoSQL Database
15 |
16 | Oracle NoSQL Database binding doesn't get built by default because there is no
17 | Maven repository for it. To build the binding:
18 |
19 | 1. Download kv-ce-1.2.123.tar.gz from here:
20 |
21 | http://www.oracle.com/technetwork/database/nosqldb/downloads/index.html
22 |
23 | 2. Untar kv-ce-1.2.123.tar.gz and install kvclient-1.2.123.jar in your local
24 | maven repository:
25 |
26 | tar xfvz kv-ce-1.2.123.tar.gz
27 | mvn install:install-file -Dfile=kv-1.2.123/lib/kvclient-1.2.123.jar \
28 | -DgroupId=com.oracle -DartifactId=kvclient -Dversion=1.2.123
29 | -Dpackaging=jar
30 |
31 | 3. Uncomment `nosqldb` and run `mvn clean package`.
32 |
--------------------------------------------------------------------------------
/NOTICE.txt:
--------------------------------------------------------------------------------
1 | =========================================================================
2 | NOTICE file for use with, and corresponding to Section 4 of,
3 | the Apache License, Version 2.0,
4 | in this case for the YCSB-TS project.
5 | =========================================================================
6 |
7 | This product includes software developed by
8 | the YCSB contributors (https://github.com/brianfrankcooper/YCSB/graphs/contributors)
9 | Copyright (c) 2015 YCSB contributors All rights reserved.
10 |
11 | This product includes software developed by
12 | Yahoo! Inc. (www.yahoo.com)
13 | Copyright (c) 2010 Yahoo! Inc. All rights reserved.
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # YCSB-TS
2 | [](https://travis-ci.org/TSDBBench/YCSB-TS)
3 |
4 | YCSB-TS is a fork of [YCSB](http://github.com/brianfrankcooper/YCSB) that is adopted to use basic time domain functions and support timestamps and timeranges.
5 | It is used in [TSDBBench](https://tsdbbench.github.io/) to measure the performance of time series databases (TSDBs).
6 | To achieve this, many new workload options are introduced, as well as bindings for many TSDBs.
7 |
8 | The benchmark is usually executed using [Overlord](https://github.com/TSDBBench/Overlord).
9 |
10 | Supported databases are tracked at .
11 |
12 | ## Getting Started
13 |
14 | * To build the full distribution, with all database bindings:
15 | `mvn clean package`
16 | * The usage is the same as original YCSB, see the documentation [here](http://github.com/brianfrankcooper/YCSB).
17 | * new workload options are documented in [workload_template](workloads/workload_template) and [CoreWorkload.java](core/src/main/java/com/yahoo/ycsb/workloads/CoreWorkload.java)
18 |
19 | ## Additional Information
20 |
21 | * Everything was tested and used on Debian Jessie x64, but should work on Ubuntu.
22 | * Ubuntu has different package names for a lot of the packages, you need to find and change them
23 | * Logfiles/Benchmark Results are stored compressed as .ydc Files
24 |
25 | ## Development Information
26 |
27 | * See the [README.md of Overlord](https://github.com/TSDBBench/Overlord) for more information
28 | * The original tests are untouched and therefore not working and should be fixed
29 | * [Adding a New Database](adding_a_database.md)
30 |
31 | ## Funding
32 |
33 | TSDBBench received funding from the
34 | [Federal Ministry for Economic Affairs and Energy](http://www.bmwi.de/Navigation/EN/Home/home.html)
35 | in the context of the project [NEMAR](https://www.nemar.de/).
36 |
37 | 
38 |
39 | ## Related Links
40 |
41 | * [YCSB on Github](http://github.com/brianfrankcooper/YCSB)
42 | * [YCSB Wiki on Github](http://wiki.github.com/brianfrankcooper/YCSB)
43 | * [Overlord](https://github.com/TSDBBench/Overlord)
44 | * [Comparison of TSDBs (Andreas Bader)](http://www2.informatik.uni-stuttgart.de/cgi-bin/NCSTRL/NCSTRL_view.pl?id=DIP-3729&mod=0&engl=0&inst=FAK)
45 | * [Survey and Comparison of Open Source TSDBs (Andreas Bader, Oliver Kopp, Michael Falkenthal)](http://www2.informatik.uni-stuttgart.de/cgi-bin/NCSTRL/NCSTRL_view.pl?id=INPROC-2017-06&mod=0&engl=0&inst=IPVS)
46 | * [Ultimate Comparison of TSDBs](https://tsdbbench.github.io/Ultimate-TSDB-Comparison/)
47 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | remote_theme: adr/slate
2 | anchor: true
3 |
--------------------------------------------------------------------------------
/akumuli/akumuli-binding.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/akumuli/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.yahoo.ycsb
6 | binding-parent
7 | 0.4.0
8 | ../binding-parent
9 |
10 |
11 | akumuli-binding
12 | Akumuli Binding
13 |
14 |
15 |
16 | com.yahoo.ycsb
17 | core
18 | ${project.version}
19 | provided
20 |
21 |
22 | org.apache.httpcomponents
23 | httpclient
24 | 4.5.2
25 |
26 |
27 | org.json
28 | json
29 | 20151123
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/akumuli/src/main/java/com/yahoo/ycsb/db/Test.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.ycsb.db;
2 |
3 | import java.sql.Timestamp;
4 | import java.util.ArrayList;
5 | import java.util.HashMap;
6 | //import java.time.Instant;
7 | import java.util.concurrent.TimeUnit;
8 |
9 | import com.yahoo.ycsb.ByteIterator;
10 | import com.yahoo.ycsb.DBException;
11 | import com.yahoo.ycsb.StringByteIterator;
12 |
13 | public class Test {
14 |
15 | public static void main(String[] args) throws DBException {
16 |
17 | AkumuliClient client = new AkumuliClient();
18 | client.init();
19 |
20 | HashMap tagsInsert = new HashMap();
21 | tagsInsert.put("tag1_Key", new StringByteIterator("tag1_Val1"));
22 | HashMap tagsInsert2 = new HashMap();
23 | tagsInsert2.put("tag1_Key", new StringByteIterator("tag1_Val2"));
24 |
25 | // Insert tests
26 | System.out.println(client.insert("metric1", Timestamp.valueOf("2001-10-19 20:15:00"), 1.0, tagsInsert));
27 | System.out.println(client.insert("metric1", Timestamp.valueOf("2001-10-19 20:15:00"), 1.5, tagsInsert2));
28 | System.out.println(client.insert("metric1", Timestamp.valueOf("2013-01-20 00:00:00"), 2.0, tagsInsert));
29 | System.out.println(client.insert("metric2", Timestamp.valueOf("2016-04-03 19:56:00"), 3.0, tagsInsert));
30 |
31 | System.out.println(client.insert("metric2", Timestamp.valueOf("2016-04-04 09:30:00"), 1.5, tagsInsert2));
32 | System.out.println(client.insert("metric2", Timestamp.valueOf("2016-04-04 09:40:00"), 2.5, tagsInsert2));
33 | System.out.println(client.insert("metric2", Timestamp.valueOf("2016-04-04 09:50:00"), 3.5, tagsInsert2));
34 | System.out.println(client.insert("metric2", Timestamp.valueOf("2016-04-04 09:55:00"), 4.5, tagsInsert2));
35 |
36 |
37 |
38 | HashMap> tagsQuery = new HashMap>();
39 | ArrayList tagValues = new ArrayList();
40 | tagValues.add("tag1_Val1");
41 | tagValues.add("tag1_Val2");
42 | tagsQuery.put("tag1_Key", tagValues);
43 |
44 | // Read tests
45 | System.out.println(client.read("metric1", Timestamp.valueOf("2001-10-19 20:15:00"), tagsQuery));
46 | System.out.println(client.read("metric2", Timestamp.valueOf("2016-04-03 19:56:00"), tagsQuery));
47 |
48 | // Scan tests
49 | client.scan("metric2", Timestamp.valueOf("2016-04-04 09:30:00"),
50 | Timestamp.valueOf("2016-04-04 10:00:00"), tagsQuery, true, false, false, 15, TimeUnit.MINUTES);
51 |
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/atsd/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.yahoo.ycsb
5 | binding-parent
6 | 0.4.0
7 | ../binding-parent
8 |
9 | atsd-binding
10 |
11 |
12 | com.yahoo.ycsb
13 | core
14 | ${project.version}
15 | provided
16 |
17 |
18 | com.axibase
19 | atsd-api-java
20 | 1.0.0
21 |
22 |
23 | ATSD Binding
24 |
25 |
--------------------------------------------------------------------------------
/atsd/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/binding-parent/binding-parent.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/binding-parent/datastore-specific-descriptor/datastore-specific-descriptor.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/binding-parent/datastore-specific-descriptor/pom.xml:
--------------------------------------------------------------------------------
1 |
17 |
19 | 4.0.0
20 |
21 |
22 | com.yahoo.ycsb
23 | root
24 | 0.4.0
25 | ../../
26 |
27 |
28 | datastore-specific-descriptor
29 | Per Datastore Binding descriptor
30 | jar
31 |
32 |
33 | This module contains the assembly descriptor used by the individual components
34 | to build binding-specific distributions.
35 |
36 |
37 |
38 | com.yahoo.ycsb
39 | core
40 | ${project.version}
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/binding-parent/datastore-specific-descriptor/src/main/resources/assemblies/datastore-specific-assembly.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
21 | dist
22 | true
23 | ycsb-${artifactId}-${version}
24 |
25 |
26 | README.md
27 |
28 |
29 |
30 |
31 |
32 | ..
33 |
34 | 0644
35 |
36 | LICENSE.txt
37 | NOTICE.txt
38 |
39 |
40 |
41 | ../bin
42 | bin
43 | 0755
44 |
45 | ycsb
46 |
47 |
48 |
49 | ../workloads
50 | workloads
51 | 0644
52 |
53 |
54 | src/main/conf
55 | conf
56 | 0644
57 |
58 |
59 |
60 |
61 | lib
62 |
63 | com.yahoo.ycsb:core
64 |
65 | provided
66 | true
67 |
68 |
69 | lib
70 |
71 | *:jar:*
72 |
73 |
74 | *:sources
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/blueflood/blueflood-binding.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/blueflood/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.yahoo.ycsb
7 | binding-parent
8 | 0.4.0
9 | ../binding-parent
10 |
11 |
12 | blueflood-binding
13 | Blueflood Binding
14 | jar
15 |
16 |
17 |
18 | org.json
19 | json
20 | 20140107
21 |
22 |
23 | org.apache.httpcomponents
24 | httpclient
25 | 4.5
26 |
27 |
28 | com.yahoo.ycsb
29 | core
30 | ${project.version}
31 | provided
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/core/core.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
21 | 4.0.0
22 |
23 | com.yahoo.ycsb
24 | root
25 | 0.4.0
26 |
27 |
28 | core
29 | Core YCSB
30 | jar
31 |
32 |
33 | 1.9.4
34 |
35 |
36 |
37 |
38 | org.codehaus.jackson
39 | jackson-mapper-asl
40 | ${jackson.api.version}
41 |
42 |
43 | org.codehaus.jackson
44 | jackson-core-asl
45 | ${jackson.api.version}
46 |
47 |
48 | org.testng
49 | testng
50 | 6.1.1
51 | test
52 |
53 |
54 | org.hdrhistogram
55 | HdrHistogram
56 | 2.1.4
57 |
58 |
59 | net.sourceforge.javacsv
60 | javacsv
61 | 2.0
62 |
63 |
64 |
65 |
66 |
67 | org.apache.maven.plugins
68 | maven-assembly-plugin
69 | ${maven.assembly.version}
70 |
71 |
72 | jar-with-dependencies
73 |
74 | false
75 |
76 |
77 |
78 | package
79 |
80 | single
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/ByteArrayByteIterator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 | package com.yahoo.ycsb;
18 |
19 | public class ByteArrayByteIterator extends ByteIterator {
20 | final int len;
21 | byte[] str;
22 | int off;
23 |
24 | public ByteArrayByteIterator(byte[] s) {
25 | this.str = s;
26 | this.off = 0;
27 | this.len = s.length;
28 | }
29 |
30 | public ByteArrayByteIterator(byte[] s, int off, int len) {
31 | this.str = s;
32 | this.off = off;
33 | this.len = off + len;
34 | }
35 |
36 | @Override
37 | public boolean hasNext() {
38 | return off < len;
39 | }
40 |
41 | @Override
42 | public byte nextByte() {
43 | byte ret = str[off];
44 | off++;
45 | return ret;
46 | }
47 |
48 | @Override
49 | public long bytesLeft() {
50 | return len - off;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/DBException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb;
19 |
20 | /**
21 | * Something bad happened while interacting with the database.
22 | */
23 | public class DBException extends Exception {
24 | /**
25 | *
26 | */
27 | private static final long serialVersionUID = 6646883591588721475L;
28 |
29 | public DBException(String message) {
30 | super(message);
31 | }
32 |
33 | public DBException() {
34 | super();
35 | }
36 |
37 | public DBException(String message, Throwable cause) {
38 | super(message, cause);
39 | }
40 |
41 | public DBException(Throwable cause) {
42 | super(cause);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/DBFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb;
19 |
20 | import java.util.Properties;
21 |
22 | /**
23 | * Creates a DB layer by dynamically classloading the specified DB class.
24 | */
25 | public class DBFactory {
26 | @SuppressWarnings("unchecked")
27 | public static DB newDB(String dbname, Properties properties) throws UnknownDBException {
28 | ClassLoader classLoader = DBFactory.class.getClassLoader();
29 |
30 | DB ret = null;
31 |
32 | try {
33 | Class dbclass = classLoader.loadClass(dbname);
34 | //System.out.println("dbclass.getName() = " + dbclass.getName());
35 |
36 | ret = (DB) dbclass.newInstance();
37 | }
38 | catch (Exception e) {
39 | e.printStackTrace();
40 | return null;
41 | }
42 |
43 | ret.setProperties(properties);
44 |
45 | return new DBWrapper(ret);
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/InputStreamByteIterator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 | package com.yahoo.ycsb;
18 |
19 | import java.io.InputStream;
20 |
21 | public class InputStreamByteIterator extends ByteIterator {
22 | long len;
23 | InputStream ins;
24 | long off;
25 |
26 | public InputStreamByteIterator(InputStream ins, long len) {
27 | this.len = len;
28 | this.ins = ins;
29 | off = 0;
30 | }
31 |
32 | @Override
33 | public boolean hasNext() {
34 | return off < len;
35 | }
36 |
37 | @Override
38 | public byte nextByte() {
39 | int ret;
40 | try {
41 | ret = ins.read();
42 | }
43 | catch (Exception e) {
44 | throw new IllegalStateException(e);
45 | }
46 | if (ret == -1) {
47 | throw new IllegalStateException("Past EOF!");
48 | }
49 | off++;
50 | return (byte) ret;
51 | }
52 |
53 | @Override
54 | public long bytesLeft() {
55 | return len - off;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/RandomByteIterator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 | package com.yahoo.ycsb;
18 |
19 | /**
20 | * A ByteIterator that generates a random sequence of bytes.
21 | */
22 | public class RandomByteIterator extends ByteIterator {
23 | private long len;
24 | private long off;
25 | private int bufOff;
26 | private byte[] buf;
27 |
28 | public RandomByteIterator(long len) {
29 | this.len = len;
30 | this.buf = new byte[6];
31 | this.bufOff = buf.length;
32 | fillBytes();
33 | this.off = 0;
34 | }
35 |
36 | @Override
37 | public boolean hasNext() {
38 | return (off + bufOff) < len;
39 | }
40 |
41 | private void fillBytesImpl(byte[] buffer, int base) {
42 | // we need A-Za-z0-9, which convertes to the range (Ascii/UTF-8):
43 | // 0-9 48-57
44 | // A-Z 65-90
45 | // a-z 97-122
46 | try {
47 | buffer[base + 0] = (byte) this.getRandAN();
48 | buffer[base + 1] = (byte) this.getRandAN();
49 | buffer[base + 2] = (byte) this.getRandAN();
50 | buffer[base + 3] = (byte) this.getRandAN();
51 | buffer[base + 4] = (byte) this.getRandAN();
52 | buffer[base + 5] = (byte) this.getRandAN();
53 | } catch (ArrayIndexOutOfBoundsException e) { /* ignore it */ }
54 | }
55 |
56 | private void fillBytes() {
57 | if (bufOff == buf.length) {
58 | fillBytesImpl(buf, 0);
59 | bufOff = 0;
60 | off += buf.length;
61 | }
62 | }
63 |
64 | public byte nextByte() {
65 | fillBytes();
66 | bufOff++;
67 | return buf[bufOff - 1];
68 | }
69 |
70 | @Override
71 | public int nextBuf(byte[] buffer, int bufferOffset) {
72 | int ret;
73 | if (len - off < buffer.length - bufferOffset) {
74 | ret = (int) (len - off);
75 | } else {
76 | ret = buffer.length - bufferOffset;
77 | }
78 | int i;
79 | for (i = 0; i < ret; i += 6) {
80 | fillBytesImpl(buffer, i + bufferOffset);
81 | }
82 | off += ret;
83 | return ret + bufferOffset;
84 | }
85 |
86 | @Override
87 | public long bytesLeft() {
88 | return len - off - bufOff;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/StringByteIterator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb;
19 |
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | public class StringByteIterator extends ByteIterator {
24 | String str;
25 | int off;
26 |
27 | public StringByteIterator(String s) {
28 | this.str = s;
29 | this.off = 0;
30 | }
31 |
32 | /**
33 | * Put all of the entries of one map into the other, converting
34 | * String values into ByteIterators.
35 | */
36 | public static void putAllAsByteIterators(Map out, Map in) {
37 | for (String s : in.keySet()) {
38 | out.put(s, new StringByteIterator(in.get(s)));
39 | }
40 | }
41 |
42 | /**
43 | * Put all of the entries of one map into the other, converting
44 | * ByteIterator values into Strings.
45 | */
46 | public static void putAllAsStrings(Map out, Map in) {
47 | for (String s : in.keySet()) {
48 | out.put(s, in.get(s).toString());
49 | }
50 | }
51 |
52 | /**
53 | * Create a copy of a map, converting the values from Strings to
54 | * StringByteIterators.
55 | */
56 | public static HashMap getByteIteratorMap(Map m) {
57 | HashMap ret =
58 | new HashMap();
59 |
60 | for (String s : m.keySet()) {
61 | ret.put(s, new StringByteIterator(m.get(s)));
62 | }
63 | return ret;
64 | }
65 |
66 | /**
67 | * Create a copy of a map, converting the values from
68 | * StringByteIterators to Strings.
69 | */
70 | public static HashMap getStringMap(Map m) {
71 | HashMap ret = new HashMap();
72 |
73 | for (String s : m.keySet()) {
74 | ret.put(s, m.get(s).toString());
75 | }
76 | return ret;
77 | }
78 |
79 | @Override
80 | public boolean hasNext() {
81 | return off < str.length();
82 | }
83 |
84 | @Override
85 | public byte nextByte() {
86 | byte ret = (byte) str.charAt(off);
87 | off++;
88 | return ret;
89 | }
90 |
91 | @Override
92 | public long bytesLeft() {
93 | return str.length() - off;
94 | }
95 |
96 | /**
97 | * Specialization of general purpose toString() to avoid unnecessary
98 | * copies.
99 | *
100 | * Creating a new StringByteIterator, then calling toString()
101 | * yields the original String object, and does not perform any copies
102 | * or String conversion operations.
103 | *
104 | */
105 | @Override
106 | public String toString() {
107 | if (off > 0) {
108 | return super.toString();
109 | }
110 | else {
111 | return str;
112 | }
113 | }
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/TerminatorThread.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 | package com.yahoo.ycsb;
18 |
19 | import java.util.List;
20 | import java.util.Vector;
21 |
22 | /**
23 | * A thread that waits for the maximum specified time and then interrupts all the client
24 | * threads passed as the Vector at initialization of this thread.
25 | *
26 | * The maximum execution time passed is assumed to be in seconds.
27 | *
28 | * @author sudipto
29 | *
30 | */
31 | public class TerminatorThread extends Thread {
32 |
33 | private final List extends Thread> threads;
34 | private long maxExecutionTime;
35 | private Workload workload;
36 | private long waitTimeOutInMS;
37 |
38 | public TerminatorThread(long maxExecutionTime, List extends Thread> threads,
39 | Workload workload) {
40 | this.maxExecutionTime = maxExecutionTime;
41 | this.threads = threads;
42 | this.workload = workload;
43 | waitTimeOutInMS = 2000;
44 | System.err.println("Maximum execution time specified as: " + maxExecutionTime + " secs");
45 | }
46 |
47 | public void run() {
48 | try {
49 | Thread.sleep(maxExecutionTime * 1000);
50 | } catch (InterruptedException e) {
51 | System.err.println("Could not wait until max specified time, TerminatorThread interrupted.");
52 | return;
53 | }
54 | System.err.println("Maximum time elapsed. Requesting stop for the workload.");
55 | workload.requestStop();
56 | System.err.println("Stop requested for workload. Now Joining!");
57 | for (Thread t : threads) {
58 | while (t.isAlive()) {
59 | try {
60 | t.join(waitTimeOutInMS);
61 | if (t.isAlive()) {
62 | System.out.println("Still waiting for thread " + t.getName() + " to complete. " +
63 | "Workload status: " + workload.isStopRequested());
64 | }
65 | } catch (InterruptedException e) {
66 | // Do nothing. Don't know why I was interrupted.
67 | }
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/UnknownDBException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb;
19 |
20 | /**
21 | * Could not create the specified DB.
22 | */
23 | public class UnknownDBException extends Exception {
24 | /**
25 | *
26 | */
27 | private static final long serialVersionUID = 459099842269616836L;
28 |
29 | public UnknownDBException(String message) {
30 | super(message);
31 | }
32 |
33 | public UnknownDBException() {
34 | super();
35 | }
36 |
37 | public UnknownDBException(String message, Throwable cause) {
38 | super(message, cause);
39 | }
40 |
41 | public UnknownDBException(Throwable cause) {
42 | super(cause);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/Utils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb;
19 |
20 | import java.util.Random;
21 |
22 | /**
23 | * Utility functions.
24 | */
25 | public class Utils {
26 | public static final int FNV_offset_basis_32 = 0x811c9dc5;
27 | public static final int FNV_prime_32 = 16777619;
28 | public static final long FNV_offset_basis_64 = 0xCBF29CE484222325L;
29 | public static final long FNV_prime_64 = 1099511628211L;
30 | private static final Random rand = new Random();
31 | private static final ThreadLocal rng = new ThreadLocal();
32 |
33 | public static Random random() {
34 | Random ret = rng.get();
35 | if (ret == null) {
36 | ret = new Random(rand.nextLong());
37 | rng.set(ret);
38 | }
39 | return ret;
40 | }
41 |
42 | /**
43 | * Generate a random ASCII string of a given length.
44 | */
45 | public static String ASCIIString(int length) {
46 | int interval = '~' - ' ' + 1;
47 |
48 | byte[] buf = new byte[length];
49 | random().nextBytes(buf);
50 | for (int i = 0; i < length; i++) {
51 | if (buf[i] < 0) {
52 | buf[i] = (byte) ((-buf[i] % interval) + ' ');
53 | }
54 | else {
55 | buf[i] = (byte) ((buf[i] % interval) + ' ');
56 | }
57 | }
58 | return new String(buf);
59 | }
60 |
61 | /**
62 | * Hash an integer value.
63 | */
64 | public static long hash(long val) {
65 | return FNVhash64(val);
66 | }
67 |
68 | /**
69 | * 32 bit FNV hash. Produces more "random" hashes than (say) String.hashCode().
70 | *
71 | * @param val The value to hash.
72 | * @return The hash value
73 | */
74 | public static int FNVhash32(int val) {
75 | //from http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash
76 | int hashval = FNV_offset_basis_32;
77 |
78 | for (int i = 0; i < 4; i++) {
79 | int octet = val & 0x00ff;
80 | val = val >> 8;
81 |
82 | hashval = hashval ^ octet;
83 | hashval = hashval * FNV_prime_32;
84 | //hashval = hashval ^ octet;
85 | }
86 | return Math.abs(hashval);
87 | }
88 |
89 | /**
90 | * 64 bit FNV hash. Produces more "random" hashes than (say) String.hashCode().
91 | *
92 | * @param val The value to hash.
93 | * @return The hash value
94 | */
95 | public static long FNVhash64(long val) {
96 | //from http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash
97 | long hashval = FNV_offset_basis_64;
98 |
99 | for (int i = 0; i < 8; i++) {
100 | long octet = val & 0x00ff;
101 | val = val >> 8;
102 |
103 | hashval = hashval ^ octet;
104 | hashval = hashval * FNV_prime_64;
105 | //hashval = hashval ^ octet;
106 | }
107 | return Math.abs(hashval);
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/WorkloadException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb;
19 |
20 | /**
21 | * The workload tried to do something bad.
22 | */
23 | public class WorkloadException extends Exception {
24 | /**
25 | *
26 | */
27 | private static final long serialVersionUID = 8844396756042772132L;
28 |
29 | public WorkloadException(String message) {
30 | super(message);
31 | }
32 |
33 | public WorkloadException() {
34 | super();
35 | }
36 |
37 | public WorkloadException(String message, Throwable cause) {
38 | super(message, cause);
39 | }
40 |
41 | public WorkloadException(Throwable cause) {
42 | super(cause);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/generator/AcknowledgedCounterGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015 YCSB contributors. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 | package com.yahoo.ycsb.generator;
18 |
19 | import java.util.concurrent.locks.ReentrantLock;
20 |
21 | /**
22 | * A CounterGenerator that reports generated integers via lastInt()
23 | * only after they have been acknowledged.
24 | */
25 | public class AcknowledgedCounterGenerator extends CounterGenerator
26 | {
27 | /** The size of the window of pending id ack's. 2^20 = {@value} */
28 | static final int WINDOW_SIZE = Integer.rotateLeft(1, 20);
29 |
30 | /** The mask to use to turn an id into a slot in {@link #window}. */
31 | private static final int WINDOW_MASK = WINDOW_SIZE - 1;
32 |
33 | private final ReentrantLock lock;
34 | private final boolean[] window;
35 | private volatile long limit;
36 |
37 | /**
38 | * Create a counter that starts at countstart.
39 | */
40 | public AcknowledgedCounterGenerator(long countstart)
41 | {
42 | super(countstart);
43 | lock = new ReentrantLock();
44 | window = new boolean[WINDOW_SIZE];
45 | limit = countstart - 1;
46 | }
47 |
48 | /**
49 | * In this generator, the highest acknowledged counter value
50 | * (as opposed to the highest generated counter value).
51 | */
52 | @Override
53 | public long lastLong()
54 | {
55 | return limit;
56 | }
57 |
58 | /**
59 | * Make a generated counter value available via lastInt().
60 | */
61 | public void acknowledge(long value)
62 | {
63 | final int currentSlot = (int)(value & WINDOW_MASK);
64 | if (window[currentSlot] == true) {
65 | throw new RuntimeException("Too many unacknowledged insertion keys.");
66 | }
67 |
68 | window[currentSlot] = true;
69 |
70 | if (lock.tryLock()) {
71 | // move a contiguous sequence from the window
72 | // over to the "limit" variable
73 | try {
74 | // Only loop through the entire window at most once.
75 | long beforeFirstSlot = (limit & WINDOW_MASK);
76 | long index;
77 | for (index = limit + 1; index != beforeFirstSlot; ++index) {
78 | int slot = (int)(index & WINDOW_MASK);
79 | if (!window[slot]) {
80 | break;
81 | }
82 |
83 | window[slot] = false;
84 | }
85 |
86 | limit = index - 1;
87 | } finally {
88 | lock.unlock();
89 | }
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/generator/ConstantLongGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 | package com.yahoo.ycsb.generator;
18 |
19 | /**
20 | * A trivial integer generator that always returns the same value.
21 | *
22 | * @author sears
23 | *
24 | */
25 | public class ConstantLongGenerator extends LongGenerator {
26 | private final long i;
27 |
28 | /**
29 | * @param i The integer that this generator will always return.
30 | */
31 | public ConstantLongGenerator(long i) {
32 | this.i = i;
33 | }
34 |
35 | @Override
36 | public long nextLong() {
37 | return i;
38 | }
39 |
40 | @Override
41 | public double mean() {
42 | return i;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/generator/CounterGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb.generator;
19 |
20 | import java.util.concurrent.atomic.AtomicLong;
21 |
22 | /**
23 | * Generates a sequence of integers 0, 1, ...
24 | */
25 | public class CounterGenerator extends LongGenerator {
26 | final AtomicLong counter;
27 | /**
28 | * Create a counter that starts at countstart
29 | */
30 | public CounterGenerator(long countstart) {
31 | counter = new AtomicLong(countstart);
32 | setLastLong(counter.get() - 1);
33 | }
34 |
35 | /**
36 | * If the generator returns numeric (integer) values, return the next value as an int. Default is to return -1, which
37 | * is appropriate for generators that do not return numeric values.
38 | */
39 | public long nextLong() {
40 | long ret = counter.getAndIncrement();
41 | setLastLong(ret);
42 | return ret;
43 | }
44 |
45 | @Override
46 | public long lastLong() {
47 | return counter.get() - 1;
48 | }
49 |
50 | @Override
51 | public double mean() {
52 | throw new UnsupportedOperationException("Can't compute mean of non-stationary distribution!");
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/generator/DiscreteGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb.generator;
19 |
20 | import com.yahoo.ycsb.Utils;
21 | import com.yahoo.ycsb.WorkloadException;
22 |
23 | import java.util.Vector;
24 |
25 | /**
26 | * Generates a distribution by choosing from a discrete set of values.
27 | */
28 | public class DiscreteGenerator extends Generator {
29 | Vector _values;
30 | String _lastvalue;
31 |
32 | public DiscreteGenerator() {
33 | _values = new Vector();
34 | _lastvalue = null;
35 | }
36 |
37 | /**
38 | * Generate the next string in the distribution.
39 | */
40 | public String nextString() {
41 | double sum = 0;
42 |
43 | for (Pair p : _values) {
44 | sum += p._weight;
45 | }
46 |
47 | double val = Utils.random().nextDouble();
48 |
49 | for (Pair p : _values) {
50 | if (val < p._weight / sum) {
51 | return p._value;
52 | }
53 |
54 | val -= p._weight / sum;
55 | }
56 |
57 | //should never get here.
58 | System.out.println("oops. should not get here.");
59 |
60 | System.exit(0);
61 |
62 | return null;
63 | }
64 |
65 | /**
66 | * If the generator returns numeric (integer) values, return the next value as an int. Default is to return -1, which
67 | * is appropriate for generators that do not return numeric values.
68 | *
69 | * @throws WorkloadException if this generator does not support integer values
70 | */
71 | public int nextInt() throws WorkloadException {
72 | throw new WorkloadException("DiscreteGenerator does not support nextLong()");
73 | }
74 |
75 | /**
76 | * Return the previous string generated by the distribution; e.g., returned from the last nextString() call.
77 | * Calling lastString() should not advance the distribution or have any side effects. If nextString() has not yet
78 | * been called, lastString() should return something reasonable.
79 | */
80 | public String lastString() {
81 | if (_lastvalue == null) {
82 | _lastvalue = nextString();
83 | }
84 | return _lastvalue;
85 | }
86 |
87 | public void addValue(double weight, String value) {
88 | _values.add(new Pair(weight, value));
89 | }
90 |
91 | class Pair {
92 | public double _weight;
93 | public String _value;
94 |
95 | Pair(double weight, String value) {
96 | _weight = weight;
97 | _value = value;
98 | }
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/generator/ExponentialGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb.generator;
19 |
20 | import com.yahoo.ycsb.Utils;
21 |
22 | /**
23 | * A generator of an exponential distribution. It produces a sequence
24 | * of time intervals (integers) according to an exponential
25 | * distribution. Smaller intervals are more frequent than larger
26 | * ones, and there is no bound on the length of an interval. When you
27 | * construct an instance of this class, you specify a parameter gamma,
28 | * which corresponds to the rate at which events occur.
29 | * Alternatively, 1/gamma is the average length of an interval.
30 | */
31 | public class ExponentialGenerator extends LongGenerator {
32 | // What percentage of the readings should be within the most recent exponential.frac portion of the dataset?
33 | public static final String EXPONENTIAL_PERCENTILE_PROPERTY = "exponential.percentile";
34 | public static final String EXPONENTIAL_PERCENTILE_DEFAULT = "95";
35 |
36 | // What fraction of the dataset should be accessed exponential.percentile of the time?
37 | public static final String EXPONENTIAL_FRAC_PROPERTY = "exponential.frac";
38 | public static final String EXPONENTIAL_FRAC_DEFAULT = "0.8571428571"; // 1/7
39 |
40 | /**
41 | * The exponential constant to use.
42 | */
43 | double _gamma;
44 |
45 | /******************************* Constructors **************************************/
46 |
47 | /**
48 | * Create an exponential generator with a mean arrival rate of
49 | * gamma. (And half life of 1/gamma).
50 | */
51 | public ExponentialGenerator(double mean) {
52 | _gamma = 1.0 / mean;
53 | }
54 |
55 | public ExponentialGenerator(double percentile, double range) {
56 | _gamma = -Math.log(1.0 - percentile / 100.0) / range; //1.0/mean;
57 | }
58 |
59 | /****************************************************************************************/
60 |
61 | public static void main(String args[]) {
62 | ExponentialGenerator e = new ExponentialGenerator(90, 100);
63 | int j = 0;
64 | for (int i = 0; i < 1000; i++) {
65 | if (e.nextLong() < 100) {
66 | j++;
67 | }
68 | }
69 | System.out.println("Got " + j + " hits. Expect 900");
70 | }
71 |
72 | /**
73 | * Generate the next item as a long.
74 | *
75 | * @return The next item in the sequence.
76 | */
77 | public long nextLong() {
78 | return (long) (-Math.log(Utils.random().nextDouble()) / _gamma);
79 | }
80 |
81 | @Override
82 | public double mean() {
83 | return 1.0 / _gamma;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/generator/FileGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed under the Apache License, Version 2.0 (the "License"); you
3 | * may not use this file except in compliance with the License. You
4 | * may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11 | * implied. See the License for the specific language governing
12 | * permissions and limitations under the License. See accompanying
13 | * LICENSE file.
14 | */
15 |
16 | package com.yahoo.ycsb.generator;
17 |
18 | import java.io.*;
19 |
20 | /**
21 | * A generator, whose sequence is the lines of a file.
22 | */
23 | public class FileGenerator extends Generator {
24 | String filename;
25 | String current;
26 | BufferedReader reader;
27 |
28 | /**
29 | * Create a FileGenerator with the given file.
30 | * @param _filename The file to read lines from.
31 | */
32 | public FileGenerator(String _filename) {
33 | try {
34 | filename = _filename;
35 | File file = new File(filename);
36 | FileInputStream in = new FileInputStream(file);
37 | reader = new BufferedReader(new InputStreamReader(in));
38 | } catch (IOException e) {
39 | System.err.println("Exception: " + e);
40 | }
41 | }
42 |
43 | /**
44 | * Return the next string of the sequence, ie the next line of the file.
45 | */
46 | public synchronized String nextString() {
47 | try {
48 | return current = reader.readLine();
49 | } catch (NullPointerException e) {
50 | System.err.println("NullPointerException: " + filename + ':' + current);
51 | throw e;
52 | } catch (IOException e) {
53 | System.err.println("Exception: " + e);
54 | return null;
55 | }
56 | }
57 |
58 | /**
59 | * Return the previous read line.
60 | */
61 | public String lastString() {
62 | return current;
63 | }
64 |
65 | /**
66 | * Reopen the file to reuse values.
67 | */
68 | public synchronized void reloadFile() {
69 | try {
70 | System.err.println("Reload " + filename);
71 | reader.close();
72 | File file = new File(filename);
73 | FileInputStream in = new FileInputStream(file);
74 | reader = new BufferedReader(new InputStreamReader(in));
75 | } catch (IOException e) {
76 | System.err.println("Exception: " + e);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/generator/Generator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb.generator;
19 |
20 | /**
21 | * An expression that generates a sequence of string values, following some distribution (Uniform, Zipfian, Sequential, etc.)
22 | */
23 | public abstract class Generator {
24 | /**
25 | * Generate the next string in the distribution.
26 | */
27 | public abstract String nextString();
28 |
29 | /**
30 | * Return the previous string generated by the distribution; e.g., returned from the last nextString() call.
31 | * Calling lastString() should not advance the distribution or have any side effects. If nextString() has not yet
32 | * been called, lastString() should return something reasonable.
33 | */
34 | public abstract String lastString();
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/generator/HistogramGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 | package com.yahoo.ycsb.generator;
18 |
19 | import com.yahoo.ycsb.Utils;
20 |
21 | import java.io.BufferedReader;
22 | import java.io.FileReader;
23 | import java.io.IOException;
24 | import java.util.ArrayList;
25 |
26 | /**
27 | * Generate integers according to a histogram distribution. The histogram
28 | * buckets are of width one, but the values are multiplied by a block size.
29 | * Therefore, instead of drawing sizes uniformly at random within each
30 | * bucket, we always draw the largest value in the current bucket, so the value
31 | * drawn is always a multiple of block_size.
32 | *
33 | * The minimum value this distribution returns is block_size (not zero).
34 | *
35 | * Modified Nov 19 2010 by sears
36 | *
37 | * @author snjones
38 | *
39 | */
40 | public class HistogramGenerator extends LongGenerator {
41 |
42 | long block_size;
43 | long[] buckets;
44 | long area;
45 | long weighted_area = 0;
46 | double mean_size = 0;
47 |
48 | public HistogramGenerator(String histogramfile) throws IOException {
49 | BufferedReader in = new BufferedReader(new FileReader(histogramfile));
50 | String str;
51 | String[] line;
52 |
53 | ArrayList a = new ArrayList();
54 |
55 | str = in.readLine();
56 | if (str == null) {
57 | throw new IOException("Empty input file!\n");
58 | }
59 | line = str.split("\t");
60 | if (line[0].compareTo("BlockSize") != 0) {
61 | throw new IOException("First line of histogram is not the BlockSize!\n");
62 | }
63 | block_size = Integer.parseInt(line[1]);
64 |
65 | while ((str = in.readLine()) != null) {
66 | // [0] is the bucket, [1] is the value
67 | line = str.split("\t");
68 |
69 | a.add(Integer.parseInt(line[0]), Integer.parseInt(line[1]));
70 | }
71 | buckets = new long[a.size()];
72 | for (int i = 0; i < a.size(); i++) {
73 | buckets[i] = a.get(i);
74 | }
75 |
76 | in.close();
77 | init();
78 | }
79 |
80 | public HistogramGenerator(long[] buckets, int block_size) {
81 | this.block_size = block_size;
82 | this.buckets = buckets;
83 | init();
84 | }
85 |
86 | private void init() {
87 | for (int i = 0; i < buckets.length; i++) {
88 | area += buckets[i];
89 | weighted_area = i * buckets[i];
90 | }
91 | // calculate average file size
92 | mean_size = ((double) block_size) * ((double) weighted_area) / (double) (area);
93 | }
94 |
95 | @Override
96 | public long nextLong() {
97 | int number = Utils.random().nextInt((int) area);
98 | int i;
99 |
100 | for (i = 0; i < (buckets.length - 1); i++) {
101 | number -= buckets[i];
102 | if (number <= 0) {
103 | return (int) ((i + 1) * block_size);
104 | }
105 | }
106 |
107 | return (int) (i * block_size);
108 | }
109 |
110 | @Override
111 | public double mean() {
112 | return mean_size;
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/generator/IntegerGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb.generator;
19 |
20 | /**
21 | * A generator that is capable of generating ints as well as strings
22 | *
23 | * @author cooperb
24 | */
25 | public abstract class IntegerGenerator extends Generator {
26 | int lastint;
27 |
28 | /**
29 | * Set the last value generated. IntegerGenerator subclasses must use this call
30 | * to properly set the last string value, or the lastString() and lastInt() calls won't work.
31 | */
32 | protected void setLastInt(int last) {
33 | lastint = last;
34 | }
35 |
36 | /**
37 | * Return the next value as an int. When overriding this method, be sure to call setLastString() properly, or the lastString() call won't work.
38 | */
39 | public abstract int nextLong();
40 |
41 | /**
42 | * Generate the next string in the distribution.
43 | */
44 | public String nextString() {
45 | return "" + nextLong();
46 | }
47 |
48 | /**
49 | * Return the previous string generated by the distribution; e.g., returned from the last nextString() call.
50 | * Calling lastString() should not advance the distribution or have any side effects. If nextString() has not yet
51 | * been called, lastString() should return something reasonable.
52 | */
53 | @Override
54 | public String lastString() {
55 | return "" + lastInt();
56 | }
57 |
58 | /**
59 | * Return the previous int generated by the distribution. This call is unique to IntegerGenerator subclasses, and assumes
60 | * IntegerGenerator subclasses always return ints for nextLong() (e.g. not arbitrary strings).
61 | */
62 | public int lastInt() {
63 | return lastint;
64 | }
65 |
66 | /**
67 | * Return the expected value (mean) of the values this generator will return.
68 | */
69 | public abstract double mean();
70 | }
71 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/generator/LongGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb.generator;
19 |
20 | /**
21 | * A generator that is capable of generating ints as well as strings
22 | *
23 | * @author baderas
24 | *
25 | */
26 | public abstract class LongGenerator extends Generator {
27 | long lastlong;
28 |
29 | /**
30 | * Set the last value generated. IntegerGenerator subclasses must use this call
31 | * to properly set the last string value, or the lastString() and lastInt() calls won't work.
32 | */
33 | protected void setLastLong(long last) {
34 | lastlong = last;
35 | }
36 |
37 | /**
38 | * Return the next value as an int. When overriding this method, be sure to call setLastString() properly, or the lastString() call won't work.
39 | */
40 | public abstract long nextLong();
41 |
42 | /**
43 | * Generate the next string in the distribution.
44 | */
45 | public String nextString() {
46 | return "" + nextLong();
47 | }
48 |
49 | /**
50 | * Return the previous string generated by the distribution; e.g., returned from the last nextString() call.
51 | * Calling lastString() should not advance the distribution or have any side effects. If nextString() has not yet
52 | * been called, lastString() should return something reasonable.
53 | */
54 | @Override
55 | public String lastString() {
56 | return "" + lastLong();
57 | }
58 |
59 | /**
60 | * Return the previous int generated by the distribution. This call is unique to IntegerGenerator subclasses, and assumes
61 | * IntegerGenerator subclasses always return ints for nextLong() (e.g. not arbitrary strings).
62 | */
63 | public long lastLong() {
64 | return lastlong;
65 | }
66 |
67 | /**
68 | * Return the expected value (mean) of the values this generator will return.
69 | */
70 | public abstract double mean();
71 | }
72 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/generator/SkewedLatestGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb.generator;
19 |
20 | /**
21 | * Generate a popularity distribution of items, skewed to favor recent items significantly more than older items.
22 | */
23 | public class SkewedLatestGenerator extends LongGenerator {
24 | CounterGenerator _basis;
25 | ZipfianGenerator _zipfian;
26 |
27 | public SkewedLatestGenerator(CounterGenerator basis) {
28 | _basis = basis;
29 | _zipfian = new ZipfianGenerator(_basis.lastLong());
30 | nextLong();
31 | }
32 |
33 | public static void main(String[] args) {
34 | SkewedLatestGenerator gen = new SkewedLatestGenerator(new CounterGenerator(1000));
35 | for (int i = 0; i < Integer.parseInt(args[0]); i++) {
36 | System.out.println(gen.nextString());
37 | }
38 |
39 | }
40 |
41 | /**
42 | * Generate the next string in the distribution, skewed Zipfian favoring the items most recently returned by the basis generator.
43 | */
44 | public long nextLong() {
45 | long max = _basis.lastLong();
46 | long nextlong = max - _zipfian.nextLong(max+1); //+1 because range shoudl be start to end-1 (insertend is exclusive)
47 | setLastLong(nextlong);
48 | return nextlong;
49 | }
50 |
51 | @Override
52 | public double mean() {
53 | throw new UnsupportedOperationException("Can't compute mean of non-stationary distribution!");
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/generator/UniformGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb.generator;
19 |
20 | import java.util.Vector;
21 |
22 | /**
23 | * An expression that generates a random integer in the specified range
24 | */
25 | public class UniformGenerator extends Generator {
26 |
27 | Vector _values;
28 | String _laststring;
29 | UniformLongGenerator _gen;
30 |
31 |
32 | /**
33 | * Creates a generator that will return strings from the specified set uniformly randomly
34 | */
35 | @SuppressWarnings("unchecked")
36 | public UniformGenerator(Vector values) {
37 | _values = (Vector) values.clone();
38 | _laststring = null;
39 | _gen = new UniformLongGenerator(0, values.size() - 1);
40 | }
41 |
42 | /**
43 | * Generate the next string in the distribution.
44 | */
45 | public String nextString() {
46 | _laststring = _values.elementAt((int) _gen.nextLong());
47 | return _laststring;
48 | }
49 |
50 | /**
51 | * Return the previous string generated by the distribution; e.g., returned from the last nextString() call.
52 | * Calling lastString() should not advance the distribution or have any side effects. If nextString() has not yet
53 | * been called, lastString() should return something reasonable.
54 | */
55 | public String lastString() {
56 | if (_laststring == null) {
57 | nextString();
58 | }
59 | return _laststring;
60 | }
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/generator/UniformLongGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb.generator;
19 |
20 | import com.yahoo.ycsb.Utils;
21 |
22 | /**
23 | * Generates integers randomly uniform from an interval.
24 | */
25 | public class UniformLongGenerator extends LongGenerator {
26 | long _lb, _ub, _interval;
27 |
28 | /**
29 | * Creates a generator that will return integers uniformly randomly from the interval [lb,ub] inclusive (that is, lb and ub are possible values)
30 | *
31 | * @param lb the lower bound (inclusive) of generated values
32 | * @param ub the upper bound (inclusive) of generated values
33 | */
34 | public UniformLongGenerator(long lb, long ub) {
35 | _lb = lb;
36 | _ub = ub;
37 | _interval = (_ub - _lb) +1;
38 | }
39 |
40 | @Override
41 | public long nextLong() {
42 | long ret = _lb+(long)(Utils.random().nextDouble()*_interval);
43 | setLastLong(ret);
44 |
45 | return ret;
46 | }
47 |
48 | @Override
49 | public double mean() {
50 | return ((double) ((long) (_lb + _ub))) / 2.0;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/measurements/OneMeasurement.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb.measurements;
19 |
20 | import java.io.IOException;
21 | import java.util.concurrent.ConcurrentHashMap;
22 | import java.util.Map;
23 | import java.util.concurrent.atomic.AtomicInteger;
24 |
25 | import com.yahoo.ycsb.measurements.exporter.MeasurementsExporter;
26 |
27 | /**
28 | * A single measured metric (such as READ LATENCY)
29 | */
30 | public abstract class OneMeasurement {
31 |
32 | private final String _name;
33 | private final ConcurrentHashMap _returncodes;
34 |
35 | public String getName() {
36 | return _name;
37 | }
38 |
39 | /**
40 | * @param _name
41 | */
42 | public OneMeasurement(String _name) {
43 | this._name = _name;
44 | this._returncodes = new ConcurrentHashMap();
45 | }
46 |
47 | public abstract void measure(long latency);
48 |
49 | public abstract String getSummary();
50 |
51 | /**
52 | * No need for synchronization, using CHM to deal with that
53 | */
54 | public void reportReturnCode(int code) {
55 | Integer Icode = code;
56 | AtomicInteger counter = _returncodes.get(Icode);
57 |
58 | if (counter == null) {
59 | AtomicInteger other = _returncodes.putIfAbsent(Icode, counter = new AtomicInteger());
60 | if (other != null) {
61 | counter = other;
62 | }
63 | }
64 |
65 | counter.incrementAndGet();
66 | }
67 |
68 | /**
69 | * Export the current measurements to a suitable format.
70 | *
71 | * @param exporter Exporter representing the type of format to write to.
72 | * @throws IOException Thrown if the export failed.
73 | */
74 | public abstract void exportMeasurements(MeasurementsExporter exporter) throws IOException;
75 |
76 | protected final void exportReturnCodes(MeasurementsExporter exporter) throws IOException {
77 | for (Map.Entry entry : _returncodes.entrySet()) {
78 | exporter.write(getName(), "Return=" + entry.getKey(), entry.getValue().get());
79 | }
80 | }
81 | }
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/measurements/TwoInOneMeasurement.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 |
18 | package com.yahoo.ycsb.measurements;
19 |
20 | import com.yahoo.ycsb.measurements.exporter.MeasurementsExporter;
21 | import org.HdrHistogram.Recorder;
22 |
23 | import java.io.IOException;
24 |
25 | /**
26 | * delegates to 2 measurement instances.
27 | * @author nitsanw
28 | *
29 | */
30 | public class TwoInOneMeasurement extends OneMeasurement {
31 | final OneMeasurement thing1,thing2;
32 | public TwoInOneMeasurement(String name, OneMeasurement thing1,OneMeasurement thing2) {
33 | super(name);
34 | this.thing1 = thing1;
35 | this.thing2 = thing2;
36 | }
37 |
38 | /**
39 | * No need for synchronization, using CHM to deal with that
40 | *
41 | * @see com.yahoo.ycsb.OneMeasurement#reportReturnCode(int)
42 | */
43 | public void reportReturnCode(int code) {
44 | thing1.reportReturnCode(code);
45 | }
46 |
47 | /**
48 | * It appears latency is reported in micros.
49 | * Using {@link Recorder} to support concurrent updates to histogram.
50 | *
51 | * @see com.yahoo.ycsb.OneMeasurement#measure(long)
52 | */
53 | public void measure(long latencyInMicros) {
54 | thing1.measure(latencyInMicros);
55 | thing2.measure(latencyInMicros);
56 | }
57 |
58 | /**
59 | * This is called from a main thread, on orderly termination.
60 | *
61 | * @see com.yahoo.ycsb.measurements.OneMeasurement#exportMeasurements(com.yahoo.ycsb.measurements.exporter.MeasurementsExporter)
62 | */
63 | @Override
64 | public void exportMeasurements(MeasurementsExporter exporter) throws IOException {
65 | thing1.exportMeasurements(exporter);
66 | thing2.exportMeasurements(exporter);
67 | }
68 |
69 | /**
70 | * This is called periodically from the StatusThread. There's a single StatusThread per Client process.
71 | * We optionally serialize the interval to log on this opportunity.
72 | * @see com.yahoo.ycsb.measurements.OneMeasurement#getSummary()
73 | */
74 | @Override
75 | public String getSummary() {
76 | return thing1.getSummary() + "\n" + thing2.getSummary();
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/measurements/exporter/JSONArrayMeasurementsExporter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 | package com.yahoo.ycsb.measurements.exporter;
18 |
19 | import org.codehaus.jackson.JsonFactory;
20 | import org.codehaus.jackson.JsonGenerator;
21 | import org.codehaus.jackson.util.DefaultPrettyPrinter;
22 |
23 | import java.io.BufferedWriter;
24 | import java.io.IOException;
25 | import java.io.OutputStream;
26 | import java.io.OutputStreamWriter;
27 |
28 | /**
29 | * Export measurements into a machine readable JSON Array of measurement objects.
30 | */
31 | public class JSONArrayMeasurementsExporter implements MeasurementsExporter {
32 |
33 | private JsonFactory factory = new JsonFactory();
34 | private JsonGenerator g;
35 |
36 | public JSONArrayMeasurementsExporter(OutputStream os) throws IOException {
37 | BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
38 | g = factory.createJsonGenerator(bw);
39 | g.setPrettyPrinter(new DefaultPrettyPrinter());
40 | g.writeStartArray();
41 | }
42 |
43 | public void write(String metric, String measurement, long i) throws IOException {
44 | g.writeStartObject();
45 | g.writeStringField("metric", metric);
46 | g.writeStringField("measurement", measurement);
47 | g.writeNumberField("value", i);
48 | g.writeEndObject();
49 | }
50 |
51 | public void write(String metric, String measurement, double d) throws IOException {
52 | g.writeStartObject();
53 | g.writeStringField("metric", metric);
54 | g.writeStringField("measurement", measurement);
55 | g.writeNumberField("value", d);
56 | g.writeEndObject();
57 | }
58 |
59 | public void close() throws IOException {
60 | if (g != null) {
61 | g.writeEndArray();
62 | g.close();
63 | }
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/measurements/exporter/JSONMeasurementsExporter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 | package com.yahoo.ycsb.measurements.exporter;
18 |
19 | import org.codehaus.jackson.JsonFactory;
20 | import org.codehaus.jackson.JsonGenerator;
21 | import org.codehaus.jackson.util.DefaultPrettyPrinter;
22 |
23 | import java.io.BufferedWriter;
24 | import java.io.IOException;
25 | import java.io.OutputStream;
26 | import java.io.OutputStreamWriter;
27 |
28 | /**
29 | * Export measurements into a machine readable JSON file.
30 | */
31 | public class JSONMeasurementsExporter implements MeasurementsExporter {
32 |
33 | private JsonFactory factory = new JsonFactory();
34 | private JsonGenerator g;
35 |
36 | public JSONMeasurementsExporter(OutputStream os) throws IOException {
37 |
38 | BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
39 | g = factory.createJsonGenerator(bw);
40 | g.setPrettyPrinter(new DefaultPrettyPrinter());
41 | }
42 |
43 | public void write(String metric, String measurement, long i) throws IOException {
44 | g.writeStartObject();
45 | g.writeStringField("metric", metric);
46 | g.writeStringField("measurement", measurement);
47 | g.writeNumberField("value", i);
48 | g.writeEndObject();
49 | }
50 |
51 | public void write(String metric, String measurement, double d) throws IOException {
52 | g.writeStartObject();
53 | g.writeStringField("metric", metric);
54 | g.writeStringField("measurement", measurement);
55 | g.writeNumberField("value", d);
56 | g.writeEndObject();
57 | }
58 |
59 | public void close() throws IOException {
60 | if (g != null) {
61 | g.close();
62 | }
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/measurements/exporter/MeasurementsExporter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 | package com.yahoo.ycsb.measurements.exporter;
18 |
19 | import java.io.Closeable;
20 | import java.io.IOException;
21 |
22 | /**
23 | * Used to export the collected measurements into a useful format, for example
24 | * human readable text or machine readable JSON.
25 | */
26 | public interface MeasurementsExporter extends Closeable {
27 |
28 | /**
29 | * Write a measurement to the exported format.
30 | *
31 | * @param metric Metric name, for example "READ LATENCY".
32 | * @param measurement Measurement name, for example "Average latency".
33 | * @param i Measurement to write.
34 | * @throws IOException if writing failed
35 | */
36 | void write(String metric, String measurement, long i) throws IOException;
37 |
38 | /**
39 | * Write a measurement to the exported format.
40 | *
41 | * @param metric Metric name, for example "READ LATENCY".
42 | * @param measurement Measurement name, for example "Average latency".
43 | * @param d Measurement to write.
44 | * @throws IOException if writing failed
45 | */
46 | void write(String metric, String measurement, double d) throws IOException;
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/measurements/exporter/TextMeasurementsExporter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 | package com.yahoo.ycsb.measurements.exporter;
18 |
19 | import java.io.BufferedWriter;
20 | import java.io.IOException;
21 | import java.io.OutputStream;
22 | import java.io.OutputStreamWriter;
23 |
24 | /**
25 | * Write human readable text. Tries to emulate the previous print report method.
26 | */
27 | public class TextMeasurementsExporter implements MeasurementsExporter {
28 |
29 | private BufferedWriter bw;
30 |
31 | public TextMeasurementsExporter(OutputStream os) {
32 | this.bw = new BufferedWriter(new OutputStreamWriter(os));
33 | }
34 |
35 | public void write(String metric, String measurement, long i) throws IOException {
36 | bw.write("[" + metric + "], " + measurement + ", " + i);
37 | bw.newLine();
38 | }
39 |
40 | public void write(String metric, String measurement, double d) throws IOException {
41 | bw.write("[" + metric + "], " + measurement + ", " + d);
42 | bw.newLine();
43 | }
44 |
45 | public void close() throws IOException {
46 | this.bw.close();
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/core/src/main/java/com/yahoo/ycsb/workloads/ConstantOccupancyWorkload.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you
5 | * may not use this file except in compliance with the License. You
6 | * may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License. See accompanying
15 | * LICENSE file.
16 | */
17 | package com.yahoo.ycsb.workloads;
18 |
19 | import com.yahoo.ycsb.Client;
20 | import com.yahoo.ycsb.WorkloadException;
21 | import com.yahoo.ycsb.generator.IntegerGenerator;
22 | import com.yahoo.ycsb.generator.LongGenerator;
23 |
24 | import java.util.Properties;
25 |
26 | /**
27 | * A disk-fragmenting workload.
28 | *
29 | * Properties to control the client:
30 | *
31 | *
32 | *
disksize: how many bytes of storage can the disk store? (default 100,000,000)
33 | *
occupancy: what fraction of the available storage should be used? (default 0.9)
34 | *
requestdistribution: what distribution should be used to select the records to operate on - uniform, zipfian or latest (default: histogram)
35 | *