Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
package Benchmark;
import java.io.IOException;
import org.epics.pvaClient.PvaClient;
import org.epics.pvaClient.PvaClientPut;
import org.epics.pvaClient.PvaClientPutData;
public class myPVAClient {
public static void main(String[] args) {
//String archiverAppliance = "muonio.rz-berlin.mpg.de";
//String archiverAppliance = "aa0s.rz-berlin.mpg.de";
String archiverAppliance = "aa0.fhi-berlin.mpg.de";
String providerName = "pva";
PvaClient pva = PvaClient.get(providerName);
boolean initialSampling = false; // true if the PV is not archived yet and an initial sampling needs to be conducted
long timeAtStartOfWhile, timePassedInWhileLoop;
long timeSpentInForLoop=0, timeSpentForPut=0, timeAtStartOfForLoop=0, timeAtStartOfPut=0, timeSum=0;
double oneSecond = Math.pow(10, 9); // duration of 1 s in nano seconds
double putThisManySamples;
double[] delaysBetweenTwoSamples;
if ( initialSampling ) {
putThisManySamples = 100.0;
} else {
putThisManySamples = 10.0;
}
String recordName;
int arraySize = 128; // = 1 KB
//int arraySize = 12800; // =100 KB
//int arraySize = 131072; // = 1 MB
//int arraySize = 1310720; // = 10 MB
//int arraySize = 13107200; // = 100 MB
switch (arraySize) {
case 128:
recordName = "myNTScalarArray_1KB";
break;
case 12800:
recordName = "myNTScalarArray_100KB";
break;
case 131072:
recordName = "myNTScalarArray_1MB";
break;
case 1310720:
recordName = "myNTScalarArray_10MB";
break;
case 13107200:
recordName = "myNTScalarArray_100MB";
break;
default:
recordName = "";
break;
}
try {
PvaClientPut put = pva.channel(recordName, providerName).put();
PvaClientPutData putData = put.getData();
double value = 0.0;
if ( initialSampling ) {
delaysBetweenTwoSamples = new double[]{1.0};
} else {
delaysBetweenTwoSamples = new double[]{1.0, 0.1, 0.01};
}
double[] data = new double[arraySize];
int numberOfEvents = 0;
int lostEvents = 0;
if ( ! initialSampling ) {
try {
System.out.println("Sampling period: " + PVDetails.getPVDetails(archiverAppliance,
recordName, "Sampling period:").getDouble("value") + " s");
} catch (IOException e) {
e.printStackTrace();
}
}
for (double delay : delaysBetweenTwoSamples) {
if ( ! initialSampling ) {
try {
numberOfEvents = PVDetails.getPVDetails(archiverAppliance, recordName, "How many events so far?").getInt("value");
lostEvents = PVDetails.getPVDetails(archiverAppliance, recordName, "How many events lost totally so far?").getInt("value");
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Before resuming thread: " + numberOfEvents + " " + lostEvents);
}
timeAtStartOfWhile = System.nanoTime();
timePassedInWhileLoop = 0;
int howMany = 0;
while ( timePassedInWhileLoop <= putThisManySamples * oneSecond ) {
timeAtStartOfForLoop = System.nanoTime();
for (int i = 0; i < data.length; ++i) {
data[i] = value;
}
timeSpentInForLoop = System.nanoTime() - timeAtStartOfForLoop;
//System.out.format("Time spent in for loop : %12.8f s%n",(double)timeSpentInForLoop*Math.pow(10,-9));
timeAtStartOfPut = System.nanoTime();
putData.putDoubleArray(data);
put.put();
timeSpentForPut = System.nanoTime() - timeAtStartOfPut;
//System.out.format("Time spent for Put : %12.8f s%n",(double)timeSpentForPut*Math.pow(10,-9));
timeSum = timeSum + timeSpentInForLoop + timeSpentForPut;
value++;
if ( initialSampling ) {
System.out.println("value="+value);
}
howMany++;
if (delay > 0) {
try {
Thread.sleep((long) (delay * 1000.0));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
timePassedInWhileLoop = System.nanoTime() - timeAtStartOfWhile;
} // end of while loop
if ( ! initialSampling ) {
System.out.println("@run: This is how many events should have been put: " + howMany);
System.out.format("@run: Average time per for loop plus put: %12.8f s%n", (double)(timeSum/howMany)*Math.pow(10,-9));
}
try {
Thread.sleep(5*1000); // 1000 * 60 = 1 min
} catch (InterruptedException e) {
e.printStackTrace();
}
if ( ! initialSampling ) {
try {
numberOfEvents = PVDetails.getPVDetails(archiverAppliance, recordName, "How many events so far?").getInt("value") - numberOfEvents;
lostEvents = PVDetails.getPVDetails(archiverAppliance, recordName, "How many events lost totally so far?").getInt("value") - lostEvents;
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("arraySize=" + arraySize + " delay=" + delay + " # events="+
numberOfEvents + " # lost events=" + lostEvents);
}
} // end of for loop
} catch (RuntimeException e) {
System.err.println("exception " + e.getMessage());
e.printStackTrace(System.err);
System.exit(1);;
}
System.out.println("\n_____putting data to the PV "+recordName+" is done_______");
pva.destroy();
}
}