Permalink
Cannot retrieve contributors at this time
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?
Benchmark/myPVAClient_NTND.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
165 lines (142 sloc)
7.05 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Benchmark; | |
import org.epics.pvaClient.PvaClient; | |
import org.epics.pvaClient.PvaClientChannel; | |
import org.epics.pvaClient.PvaClientPut; | |
import org.epics.pvaClient.PvaClientPutData; | |
import org.epics.pvdata.pv.PVDoubleArray; | |
import org.epics.pvdata.pv.PVUnion; | |
import java.io.IOException; | |
public class myPVAClient_NTND { | |
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 = "myNTNDArray_1KB"; | |
break; | |
case 12800: | |
recordName = "myNTNDArray_100KB"; | |
break; | |
case 131072: | |
recordName = "myNTNDArray_1MB"; | |
break; | |
case 1310720: | |
recordName = "myNTNDArray_10MB"; | |
break; | |
case 13107200: | |
recordName = "myNTNDArray_100MB"; | |
break; | |
default: | |
recordName = ""; | |
break; | |
} | |
try { | |
PvaClientChannel pvaChannel = pva.channel(recordName, providerName); | |
PvaClientPut put = pvaChannel.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.getPVStructure().getSubField(PVUnion.class,"value").select(PVDoubleArray.class, "doubleValue").put(0, data.length, data, 0); | |
put.put(); | |
putData.getPVStructure().getSubField(PVUnion.class,"value").postPut(); | |
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(); | |
} | |
} |