You need to sign in or sign up before continuing.
Commit d7f831b2 authored by NILANJAN DAW's avatar NILANJAN DAW

Async mode StorageService made cache flag aware. Asyc Storage no more sharing stubs.

parent fff1436f
app.name="HPDOS-Client" app.name="HPDOS-Client"
app.version="0.1.4" app.version="0.1.4"
app.cache=1
app.thread_count=10 app.thread_count=10
app.rps=1000 app.rps=1000
app.runtime=10 app.runtime=10
......
...@@ -53,7 +53,7 @@ dependencies { ...@@ -53,7 +53,7 @@ dependencies {
application { application {
// Define the main class for the application. // Define the main class for the application.
mainClass = 'HpdosClient.ClientRunnerSync' mainClass = 'HpdosClient.ClientRunner'
} }
sourceSets { sourceSets {
......
...@@ -38,6 +38,7 @@ public class ClientRunnerSync { ...@@ -38,6 +38,7 @@ public class ClientRunnerSync {
public boolean experimentEnded = false; public boolean experimentEnded = false;
private Queue<Long> createTime, updateTime, readTime, deleteTime; private Queue<Long> createTime, updateTime, readTime, deleteTime;
private final Properties properties; private final Properties properties;
private boolean cacheEnabled;
public ClientRunnerSync() { public ClientRunnerSync() {
clientID = UUID.randomUUID().toString(); clientID = UUID.randomUUID().toString();
...@@ -46,6 +47,7 @@ public class ClientRunnerSync { ...@@ -46,6 +47,7 @@ public class ClientRunnerSync {
InputStream inputStream = new FileInputStream(propertiesFile); InputStream inputStream = new FileInputStream(propertiesFile);
properties.load(inputStream); properties.load(inputStream);
parallelCount = Integer.parseInt((String) properties.get("app.thread_count")); parallelCount = Integer.parseInt((String) properties.get("app.thread_count"));
cacheEnabled = properties.get("app.cache").equals("1");
runtime = Integer.parseInt((String) properties.get("app.runtime")); runtime = Integer.parseInt((String) properties.get("app.runtime"));
cCreate = Integer.parseInt((String) properties.get("app.cycle_create")); cCreate = Integer.parseInt((String) properties.get("app.cycle_create"));
cRead = Integer.parseInt((String) properties.get("app.cycle_read")); cRead = Integer.parseInt((String) properties.get("app.cycle_read"));
...@@ -79,7 +81,7 @@ public class ClientRunnerSync { ...@@ -79,7 +81,7 @@ public class ClientRunnerSync {
return new String(data); return new String(data);
} }
public double runExperiment(String id, long experimentStartTime) { public double runExperiment(String id, long experimentStartTime) {
StorageServiceSync storageService = new StorageServiceSync(this.clientID); StorageServiceSync storageService = new StorageServiceSync(this.clientID, this.cacheEnabled);
storageService.initStorage(); storageService.initStorage();
String value = createString(), updatedValue = createString(); String value = createString(), updatedValue = createString();
for (;;) { for (;;) {
...@@ -112,7 +114,8 @@ public class ClientRunnerSync { ...@@ -112,7 +114,8 @@ public class ClientRunnerSync {
if ((currentTime - experimentStartTime) >= runtime * 1000L) if ((currentTime - experimentStartTime) >= runtime * 1000L)
break; break;
} }
System.out.println(storageService.getCache().stats()); if (this.cacheEnabled)
System.out.println(storageService.getCache().stats());
storageService.cleanup(); storageService.cleanup();
return 0; return 0;
} }
...@@ -174,6 +177,7 @@ public class ClientRunnerSync { ...@@ -174,6 +177,7 @@ public class ClientRunnerSync {
ClientRunnerSync clientRunner = new ClientRunnerSync(); ClientRunnerSync clientRunner = new ClientRunnerSync();
System.out.println(clientRunner.getGreeting()); System.out.println(clientRunner.getGreeting());
System.out.println("Using Sync Server. Thread count: " + parallelCount + " runtime: " + runtime + "s"); System.out.println("Using Sync Server. Thread count: " + parallelCount + " runtime: " + runtime + "s");
System.out.println("cache status: " + clientRunner.cacheEnabled);
ExecutorService executorService = Executors.newFixedThreadPool(parallelCount); ExecutorService executorService = Executors.newFixedThreadPool(parallelCount);
Thread.sleep(1000); // let things settle down a bit Thread.sleep(1000); // let things settle down a bit
Set<Callable<Double>> callables = new HashSet<>(); Set<Callable<Double>> callables = new HashSet<>();
......
...@@ -38,6 +38,16 @@ public class StorageModel { ...@@ -38,6 +38,16 @@ public class StorageModel {
this.crc = crc; this.crc = crc;
} }
public StorageModel(Ack ack, String owner, int accessType) {
this.version = ack.getVersion();
this.dataSize = ack.getDataSize();
this.value = ack.getValue();
this.crc = ack.getCrc();
this.key = ack.getKey();
this.accessType = accessType;
this.owner = owner;
}
public void updateData(Ack ack) { public void updateData(Ack ack) {
this.version = ack.getVersion(); this.version = ack.getVersion();
this.dataSize = ack.getDataSize(); this.dataSize = ack.getDataSize();
......
...@@ -28,10 +28,7 @@ import io.grpc.ManagedChannelBuilder; ...@@ -28,10 +28,7 @@ import io.grpc.ManagedChannelBuilder;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.util.AbstractMap; import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
public class StorageServiceSync { public class StorageServiceSync {
...@@ -40,36 +37,39 @@ public class StorageServiceSync { ...@@ -40,36 +37,39 @@ public class StorageServiceSync {
private ManagedChannel masterChannel; private ManagedChannel masterChannel;
private ArrayList<ManagedChannel> channels; private ArrayList<ManagedChannel> channels;
private List<Follower> replicaSet; private List<Follower> replicaSet;
private final LoadingCache<String, StorageModel> cache; private boolean cacheEnabled;
private LoadingCache<String, StorageModel> cache = null;
public StorageServiceSync(String clientID) { public StorageServiceSync(String clientID, boolean cacheEnabled) {
this.clientID = clientID; this.clientID = clientID;
this.cache = CacheBuilder this.cacheEnabled = cacheEnabled;
.newBuilder() if (this.cacheEnabled)
.maximumSize(10000) this.cache = CacheBuilder
.recordStats() .newBuilder()
.build(new CacheLoader<>() { .maximumSize(10000)
@Override .recordStats()
public StorageModel load(@Nonnull String key) throws Exception { .build(new CacheLoader<>() {
int index = (int) (Math.random() * channels.size()); @Override
NetworkServiceGrpc.NetworkServiceBlockingStub stub = public StorageModel load(@Nonnull String key) throws Exception {
NetworkServiceGrpc.newBlockingStub(channels.get(index)); int index = (int) (Math.random() * channels.size());
NetworkServiceGrpc.NetworkServiceBlockingStub stub =
ArrayList<Request> request = new ArrayList<>(); NetworkServiceGrpc.newBlockingStub(channels.get(index));
request.add(RequestBuilder.buildRequest(MessageConstants.METADATA_READ,
0, 0, key, 0, MessageConstants.METADATA_ACCESS_PRIVATE, clientID, "")); ArrayList<Request> request = new ArrayList<>();
Packet requestPacket = RequestBuilder.buildPacket(request); request.add(RequestBuilder.buildRequest(MessageConstants.METADATA_READ,
Packet responsePacket = stub.readMetadata(requestPacket); 0, 0, key, 0, MessageConstants.METADATA_ACCESS_PRIVATE, clientID, ""));
Response response = responsePacket.getResponse(0); Packet requestPacket = RequestBuilder.buildPacket(request);
if (response.getStatus() == MessageConstants.STATUS_OK) { Packet responsePacket = stub.readMetadata(requestPacket);
Ack ack = response.getAck(); Response response = responsePacket.getResponse(0);
return new StorageModel(ack.getVersion(), ack.getDataSize(), ack.getKey(), if (response.getStatus() == MessageConstants.STATUS_OK) {
MessageConstants.METADATA_ACCESS_PRIVATE, clientID, ack.getCrc(), ack.getValue()); Ack ack = response.getAck();
} else { return new StorageModel(ack.getVersion(), ack.getDataSize(), ack.getKey(),
throw new IOException("Resource not found"); MessageConstants.METADATA_ACCESS_PRIVATE, clientID, ack.getCrc(), ack.getValue());
} else {
throw new IOException("Resource not found");
}
} }
} });
});
} }
...@@ -120,14 +120,31 @@ public class StorageServiceSync { ...@@ -120,14 +120,31 @@ public class StorageServiceSync {
// read back the metadata // read back the metadata
public Map.Entry<StorageModel, Long> read(String key) { public Map.Entry<StorageModel, Long> read(String key) {
long timestampReadStart = System.currentTimeMillis(); if (cacheEnabled) {
try { long timestampReadStart = System.currentTimeMillis();
StorageModel model = cache.get(key); try {
return new AbstractMap.SimpleEntry<>(model, timestampReadStart); StorageModel model = cache.get(key);
} catch (ExecutionException e) { return new AbstractMap.SimpleEntry<>(model, timestampReadStart);
e.printStackTrace(); } catch (ExecutionException e) {
e.printStackTrace();
}
return new AbstractMap.SimpleEntry<>(null, timestampReadStart);
} else {
int rnd = new Random().nextInt(this.channels.size());
NetworkServiceGrpc.NetworkServiceBlockingStub stub = NetworkServiceGrpc.newBlockingStub(channels.get(rnd));
ArrayList<Request> request = new ArrayList<>();
request.add(RequestBuilder.buildRequest(MessageConstants.METADATA_READ,
0, 0, key, 0, MessageConstants.METADATA_ACCESS_PRIVATE, this.clientID, ""));
Packet packet = RequestBuilder.buildPacket(request);
long timestampReadStart = System.currentTimeMillis();
Packet responsePacket = stub.readMetadata(packet);
if (responsePacket.getResponse(0).getStatus() == MessageConstants.STATUS_OK) {
StorageModel model = new StorageModel(responsePacket.getResponse(0).getAck(),
this.clientID, MessageConstants.METADATA_ACCESS_PRIVATE);
return new AbstractMap.SimpleEntry<>(model, timestampReadStart);
}
return new AbstractMap.SimpleEntry<>(null, timestampReadStart);
} }
return new AbstractMap.SimpleEntry<>(null, timestampReadStart);
} }
public long update(String key, String value, int version) { public long update(String key, String value, int version) {
...@@ -139,7 +156,8 @@ public class StorageServiceSync { ...@@ -139,7 +156,8 @@ public class StorageServiceSync {
long timestampCreateStart = System.currentTimeMillis(); long timestampCreateStart = System.currentTimeMillis();
NetworkServiceGrpc.NetworkServiceBlockingStub masterStub = NetworkServiceGrpc.newBlockingStub(masterChannel); NetworkServiceGrpc.NetworkServiceBlockingStub masterStub = NetworkServiceGrpc.newBlockingStub(masterChannel);
Packet responsePacket = masterStub.updateMetadata(packet); Packet responsePacket = masterStub.updateMetadata(packet);
if (responsePacket.getResponse(0).getStatus() == MessageConstants.STATUS_OK) if (this.cacheEnabled &&
responsePacket.getResponse(0).getStatus() == MessageConstants.STATUS_OK)
cache.invalidate(key); cache.invalidate(key);
return timestampCreateStart; return timestampCreateStart;
} }
...@@ -153,9 +171,9 @@ public class StorageServiceSync { ...@@ -153,9 +171,9 @@ public class StorageServiceSync {
long timestampCreateStart = System.currentTimeMillis(); long timestampCreateStart = System.currentTimeMillis();
NetworkServiceGrpc.NetworkServiceBlockingStub masterStub = NetworkServiceGrpc.newBlockingStub(masterChannel); NetworkServiceGrpc.NetworkServiceBlockingStub masterStub = NetworkServiceGrpc.newBlockingStub(masterChannel);
Packet responsePacket = masterStub.deleteMetadata(packet); Packet responsePacket = masterStub.deleteMetadata(packet);
if (responsePacket.getResponse(0).getStatus() == MessageConstants.STATUS_OK) if (this.cacheEnabled &&
responsePacket.getResponse(0).getStatus() == MessageConstants.STATUS_OK)
cache.invalidate(key); cache.invalidate(key);
return timestampCreateStart; return timestampCreateStart;
} }
} }
/*
* Copyright 2021 Nilanjan Daw, Synerg Lab, Department of CSE, IIT Bombay
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package HpdosClient;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
public class AppTest {
@Test public void testAppHasAGreeting() {
ClientRunner classUnderTest = new ClientRunner();
assertNotNull("app should have a greeting", classUnderTest.getGreeting());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment