Skip to content

Commit c83836e

Browse files
committed
[memcached] Added memcached binding.
The memcached support was extracted from PR #98 by @jbellis, with cleanups to bring it in line with current APIs and style guide. This PR also addresses issue #326.
1 parent ac4c0a7 commit c83836e

File tree

10 files changed

+611
-0
lines changed

10 files changed

+611
-0
lines changed

NOTICE.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ in this case for the YCSB project.
77
This product includes software developed by
88
Yahoo! Inc. (www.yahoo.com)
99
Copyright (c) 2010 Yahoo! Inc. All rights reserved.
10+
11+
This product includes software developed by
12+
Google Inc. (www.google.com)
13+
Copyright (c) 2015 Google Inc. All rights reserved.

bin/ycsb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ DATABASES = {
6666
"jdbc" : "com.yahoo.ycsb.db.JdbcDBClient",
6767
"kudu" : "com.yahoo.ycsb.db.KuduYCSBClient",
6868
"mapkeeper" : "com.yahoo.ycsb.db.MapKeeperClient",
69+
"memcached" : "com.yahoo.ycsb.db.MemcachedClient",
6970
"mongodb" : "com.yahoo.ycsb.db.MongoDbClient",
7071
"mongodb-async": "com.yahoo.ycsb.db.AsyncMongoDbClient",
7172
"nosqldb" : "com.yahoo.ycsb.db.NoSqlDbClient",

distribution/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ LICENSE file.
114114
<artifactId>kudu-binding</artifactId>
115115
<version>${project.version}</version>
116116
</dependency>
117+
<dependency>
118+
<groupId>com.yahoo.ycsb</groupId>
119+
<artifactId>memcached-binding</artifactId>
120+
<version>${project.version}</version>
121+
</dependency>
117122
<dependency>
118123
<groupId>com.yahoo.ycsb</groupId>
119124
<artifactId>mongodb-binding</artifactId>

memcached/README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
18+
# YCSB Memcached binding
19+
20+
This section describes how to run YCSB on memcached.
21+
22+
## 1. Install and start memcached service on the host(s)
23+
24+
Debian / Ubuntu:
25+
26+
sudo apt-get install memcached
27+
28+
RedHat / CentOS:
29+
30+
sudo yum install memcached
31+
32+
## 2. Install Java and Maven
33+
34+
See step 2 in [`../mongodb/README.md`](../mongodb/README.md).
35+
36+
## 3. Set up YCSB
37+
38+
Git clone YCSB and compile:
39+
40+
git clone http://github.com/brianfrankcooper/YCSB.git
41+
cd YCSB
42+
mvn -pl com.yahoo.ycsb:memcached-binding -am clean package
43+
44+
## 4. Load data and run tests
45+
46+
Load the data:
47+
48+
./bin/ycsb load memcached -s -P workloads/workloada > outputLoad.txt
49+
50+
Run the workload test:
51+
52+
./bin/ycsb run memcached -s -P workloads/workloada > outputRun.txt
53+
54+
## 5. memcached Connection Parameters
55+
56+
A sample configuration is provided in
57+
[`conf/memcached.properties`](conf/memcached.properties).
58+
59+
### Required params
60+
61+
- `memcached.hosts`
62+
63+
This is a comma-separated list of hosts providing the memcached interface.
64+
You can use IPs or hostnames. The port is optional and defaults to the
65+
memcached standard port of `11211` if not specified.
66+
67+
### Optional params
68+
69+
- `memcached.shutdownTimeoutMillis`
70+
71+
Shutdown timeout in milliseconds.
72+
73+
- `memcached.objectExpirationTime`
74+
75+
Object expiration time for memcached; defaults to `Integer.MAX_VALUE`.
76+
77+
- `memcached.checkOperationStatus`
78+
79+
Whether to verify the success of each operation; defaults to true.
80+
81+
- `memcached.readBufferSize`
82+
83+
Read buffer size, in bytes.
84+
85+
- `memcached.opTimeoutMillis`
86+
87+
Operation timeout, in milliseconds.
88+
89+
- `memcached.failureMode`
90+
91+
What to do with failures; this is one of `net.spy.memcached.FailureMode` enum
92+
values, which are currently: `Redistribute`, `Retry`, or `Cancel`.
93+
94+
You can set properties on the command line via `-p`, e.g.:
95+
96+
./bin/ycsb load memcached -s -P workloads/workloada \
97+
-p "memcached.hosts=127.0.0.1" > outputLoad.txt
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) 2015 YCSB contributors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you
4+
# may not use this file except in compliance with the License. You
5+
# may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12+
# implied. See the License for the specific language governing
13+
# permissions and limitations under the License. See accompanying
14+
# LICENSE file.
15+
16+
#
17+
# Sample property file for Memcached Client
18+
19+
## Mandatory parameters
20+
21+
# A comma-separated list of memcached server endpoints, each being an IP or
22+
# hostname with an optional port; the port defaults to the memcached-standard
23+
# port of 11211 if not specified.
24+
#
25+
# memcached.hosts =
26+
27+
## Optional parameters
28+
29+
# Shutdown timeout in milliseconds.
30+
#
31+
# memcached.shutdownTimeoutMillis = 30000
32+
33+
# Object expiration time for memcached; defaults to `Integer.MAX_VALUE`.
34+
#
35+
# memcached.objectExpirationTime = 2147483647
36+
37+
# Whether to verify the success of each operation; defaults to true.
38+
#
39+
# memcached.checkOperationStatus = true
40+
41+
# Read buffer size, in bytes.
42+
#
43+
# memcached.readBufferSize = 3000000
44+
45+
# Operation timeout, in milliseconds.
46+
#
47+
# memcached.opTimeoutMillis = 60000
48+
49+
# What to do with failures; this is one of `net.spy.memcached.FailureMode` enum
50+
# values, which are currently: `Redistribute`, `Retry`, or `Cancel`.
51+
#
52+
# memcached.failureMode = Redistribute

memcached/pom.xml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2015 YCSB contributors. All rights reserved.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you
6+
may not use this file except in compliance with the License. You
7+
may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14+
implied. See the License for the specific language governing
15+
permissions and limitations under the License. See accompanying
16+
LICENSE file.
17+
-->
18+
19+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
<parent>
22+
<groupId>com.yahoo.ycsb</groupId>
23+
<artifactId>binding-parent</artifactId>
24+
<version>0.6.0-SNAPSHOT</version>
25+
<relativePath>../binding-parent</relativePath>
26+
</parent>
27+
28+
<artifactId>memcached-binding</artifactId>
29+
<name>memcached binding</name>
30+
<groupId>com.yahoo.ycsb</groupId>
31+
<packaging>jar</packaging>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>log4j</groupId>
36+
<artifactId>log4j</artifactId>
37+
<version>1.2.17</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.yahoo.ycsb</groupId>
41+
<artifactId>core</artifactId>
42+
<version>${project.version}</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.codehaus.jackson</groupId>
46+
<artifactId>jackson-mapper-asl</artifactId>
47+
<version>1.9.13</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>net.spy</groupId>
51+
<artifactId>spymemcached</artifactId>
52+
<version>2.11.4</version>
53+
</dependency>
54+
</dependencies>
55+
<repositories>
56+
<repository>
57+
<id>files.couchbase.com</id>
58+
<url>http://files.couchbase.com/maven2</url>
59+
</repository>
60+
<repository>
61+
<id>repository.jboss.org</id>
62+
<url>https://repository.jboss.org/nexus/content/groups/public</url>
63+
</repository>
64+
</repositories>
65+
66+
<build>
67+
<plugins>
68+
<plugin>
69+
<groupId>org.apache.maven.plugins</groupId>
70+
<artifactId>maven-checkstyle-plugin</artifactId>
71+
<version>2.15</version>
72+
<configuration>
73+
<consoleOutput>true</consoleOutput>
74+
<configLocation>../checkstyle.xml</configLocation>
75+
<failOnViolation>true</failOnViolation>
76+
<failsOnError>true</failsOnError>
77+
</configuration>
78+
<executions>
79+
<execution>
80+
<id>validate</id>
81+
<phase>validate</phase>
82+
<goals>
83+
<goal>checkstyle</goal>
84+
</goals>
85+
</execution>
86+
</executions>
87+
</plugin>
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-assembly-plugin</artifactId>
91+
<version>${maven.assembly.version}</version>
92+
<configuration>
93+
<descriptorRefs>
94+
<descriptorRef>jar-with-dependencies</descriptorRef>
95+
</descriptorRefs>
96+
<appendAssemblyId>false</appendAssemblyId>
97+
</configuration>
98+
<executions>
99+
<execution>
100+
<phase>package</phase>
101+
<goals>
102+
<goal>single</goal>
103+
</goals>
104+
</execution>
105+
</executions>
106+
</plugin>
107+
</plugins>
108+
</build>
109+
</project>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
18+
package com.yahoo.ycsb.db;
19+
20+
import net.spy.memcached.ConnectionFactoryBuilder;
21+
import net.spy.memcached.FailureMode;
22+
23+
import java.net.InetSocketAddress;
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
27+
/**
28+
* Concrete Memcached client implementation.
29+
*/
30+
public class MemcachedClient extends MemcachedCompatibleClient {
31+
32+
public static final String HOSTS_PROPERTY = "memcached.hosts";
33+
34+
public static final int DEFAULT_PORT = 11211;
35+
36+
public static final String READ_BUFFER_SIZE_PROPERTY =
37+
"memcached.readBufferSize";
38+
public static final String DEFAULT_READ_BUFFER_SIZE = "3000000";
39+
40+
public static final String OP_TIMEOUT_PROPERTY = "memcached.opTimeoutMillis";
41+
public static final String DEFAULT_OP_TIMEOUT = "60000";
42+
43+
public static final String FAILURE_MODE_PROPERTY = "memcached.failureMode";
44+
public static final FailureMode FAILURE_MODE_PROPERTY_DEFAULT =
45+
FailureMode.Redistribute;
46+
47+
@Override
48+
protected net.spy.memcached.MemcachedClient createMemcachedClient()
49+
throws Exception {
50+
ConnectionFactoryBuilder connectionFactoryBuilder =
51+
new ConnectionFactoryBuilder();
52+
53+
connectionFactoryBuilder.setReadBufferSize(Integer.parseInt(
54+
getProperties().getProperty(READ_BUFFER_SIZE_PROPERTY,
55+
DEFAULT_READ_BUFFER_SIZE)));
56+
57+
connectionFactoryBuilder.setOpTimeout(Integer.parseInt(
58+
getProperties().getProperty(OP_TIMEOUT_PROPERTY, DEFAULT_OP_TIMEOUT)));
59+
60+
String failureString = getProperties().getProperty(FAILURE_MODE_PROPERTY);
61+
connectionFactoryBuilder.setFailureMode(
62+
failureString == null ? FAILURE_MODE_PROPERTY_DEFAULT
63+
: FailureMode.valueOf(failureString));
64+
65+
// Note: this only works with IPv4 addresses due to its assumption of
66+
// ":" being the separator of hostname/IP and port; this is not the case
67+
// when dealing with IPv6 addresses.
68+
//
69+
// TODO(mbrukman): fix this.
70+
List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>();
71+
String[] hosts = getProperties().getProperty(HOSTS_PROPERTY).split(",");
72+
for (String address : hosts) {
73+
int colon = address.indexOf(":");
74+
int port = DEFAULT_PORT;
75+
String host = address;
76+
if (colon != -1) {
77+
port = Integer.parseInt(address.substring(colon + 1));
78+
host = address.substring(0, colon);
79+
}
80+
addresses.add(new InetSocketAddress(host, port));
81+
}
82+
return new net.spy.memcached.MemcachedClient(
83+
connectionFactoryBuilder.build(), addresses);
84+
}
85+
}

0 commit comments

Comments
 (0)