Skip to content

Commit

Permalink
Merge pull request #75 from kdnilsen/deprecate-initialization-delay
Browse files Browse the repository at this point in the history
Deprecate initialization delay
  • Loading branch information
earthling-amzn authored Jul 30, 2024
2 parents c37d424 + f22f97b commit 7750c6a
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public static void main(String args[]) {
Trace.debug("Testing Arraylet with max size 4");
a = new Arraylet<Long>(t, LifeSpan.Ephemeral, 4, 56);
for (int i = 0; i < 56; i++)
a.set(i, new Long(-10 * i));
a.set(i, Long.valueOf(-10 * i));
for (int i = 55; i >= 0; i--) {
Long l = a.get(i);
String s1 = Integer.toString(i);
Expand All @@ -284,7 +284,7 @@ public static void main(String args[]) {
Trace.debug("Testing Arraylet with max size 7");
a = new Arraylet<Long>(t, LifeSpan.Ephemeral, 7, 61);
for (int i = 0; i < 61; i++)
a.set(i, new Long(-10 * i));
a.set(i, Long.valueOf(-10 * i));
for (int i = 60; i >= 0; i--) {
Long l = a.get(i);
String s1 = Integer.toString(i);
Expand All @@ -300,7 +300,7 @@ public static void main(String args[]) {
Trace.debug("Testing Arraylet with max size 0");
a = new Arraylet<Long>(t, LifeSpan.Ephemeral, 0, 61);
for (int i = 0; i < 61; i++)
a.set(i, new Long(-10 * i));
a.set(i, Long.valueOf(-10 * i));
for (int i = 60; i >= 0; i--) {
Long l = a.get(i);
String s1 = Integer.toString(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public void runExtreme() {

MemoryLog memory = memoryLog();
MemoryLog garbage = garbageLog();
MemoryLog all_threads_accumulator = (
new MemoryLog(LifeSpan.NearlyForever));
MemoryLog all_threads_accumulator = new MemoryLog(LifeSpan.NearlyForever);
all_threads_accumulator.memoryFootprint(this);

Trace.msg(1, "@ ",
Expand Down Expand Up @@ -148,35 +147,63 @@ public void runExtreme() {
Trace.msg(3, "Server stagger set to: ", server_stagger.toString(this));
}

// In addition to config.InitializationDelay(), reserve 1 second for
// variable costs of initializing every 2000 threads.
int start_delay_milliseconds = (
(config.CustomerThreads() + config.ServerThreads()) / 2);
Trace.msg(2, "starting up CustomerThreads: ", Integer.toString(config.CustomerThreads()));

RelativeTime start_delay = (config.InitializationDelay().
addMillis(this, start_delay_milliseconds));

String s = start_delay.toString(this);
Trace.msg(3, "");
Trace.msg(3, "Simulation starts in ", s);
Util.abandonEphemeralString(this, s);

AbsoluteTime now = AbsoluteTime.now(this);
AbsoluteTime start_time = now.addRelative(this, start_delay);
start_delay.garbageFootprint(this);
start_delay = null;
now.garbageFootprint(this);
now = null;
AbsoluteTime end_time = (
start_time.addRelative(this, config.SimulationDuration()));
end_time.changeLifeSpan(this, LifeSpan.NearlyForever);
// Initialize and startup all of the threads as specified in
// config.
customer_threads = new CustomerThread[config.CustomerThreads()];
Util.referenceArray(this, LifeSpan.NearlyForever, config.CustomerThreads());

AbsoluteTime staggered_customer_replacement = (
new AbsoluteTime(this, start_time));
int bq_no = config.BrowsingHistoryQueueCount() - 1;
int sq_no = config.SalesTransactionQueueCount() - 1;
for (int i = 0; i < config.CustomerThreads(); i++) {
customer_threads[i] = new CustomerThread(config, randomLong(), i, all_products, all_customers, browsing_queues[bq_no],
sales_queues[sq_no], customer_accumulator, customer_alloc_accumulator,
customer_garbage_accumulator);
if (bq_no-- == 0) {
bq_no = config.BrowsingHistoryQueueCount() - 1;
}
if (sq_no-- == 0) {
sq_no = config.SalesTransactionQueueCount() - 1;
}
}
if (customer_stagger != null) {
customer_stagger.garbageFootprint(this);
}
Trace.msg(2, "starting up ServerThreads: ",
Integer.toString(config.ServerThreads()));

AbsoluteTime staggered_product_replacement = (
new AbsoluteTime(this, start_time));
server_threads = new ServerThread[config.ServerThreads()];
Util.referenceArray(this, LifeSpan.NearlyForever, config.ServerThreads());

bq_no = config.BrowsingHistoryQueueCount() - 1;
sq_no = config.SalesTransactionQueueCount() - 1;
for (int i = 0; i < config.ServerThreads(); i++) {
server_threads[i] = new ServerThread(config, randomLong(), i, all_products, all_customers, browsing_queues[bq_no],
sales_queues[sq_no], server_accumulator, server_alloc_accumulator,
server_garbage_accumulator);
if (bq_no-- == 0)
bq_no = config.BrowsingHistoryQueueCount() - 1;
if (sq_no-- == 0)
sq_no = config.SalesTransactionQueueCount() - 1;
}

if (config.PhasedUpdates()) {
update_thread = new UpdateThread(config, randomLong(), all_products, all_customers);
} else {
update_thread = null;
}

AbsoluteTime now = AbsoluteTime.now(this);

// Add 4 ms to conservatively approximate the time required to establish start times and start() each thread
AbsoluteTime start_time = now.addMillis(this, 4 * (config.CustomerThreads() + config.ServerThreads()));
AbsoluteTime end_time = start_time.addRelative(this, config.SimulationDuration());

AbsoluteTime staggered_customer_replacement = new AbsoluteTime(this, start_time);
AbsoluteTime staggered_product_replacement = new AbsoluteTime(this, start_time);

String s;
if (config.ReportCSV()) {
s = Long.toString(start_time.microseconds());
Util.ephemeralString(this, s.length());
Expand All @@ -200,75 +227,30 @@ public void runExtreme() {
Trace.msg(2, "End simulation time: ", s);
Trace.msg(2, "");
Util.abandonEphemeralString(this, s);

Trace.msg(2, "starting up CustomerThreads: ",
Integer.toString(config.CustomerThreads()));

// Initialize and startup all of the threads as specified in
// config.
customer_threads = new CustomerThread[config.CustomerThreads()];
Util.referenceArray(this, LifeSpan.NearlyForever,
config.CustomerThreads());


// startup the customer threads
AbsoluteTime staggered_start = start_time.addMinutes(this, 0);
int bq_no = config.BrowsingHistoryQueueCount() - 1;
int sq_no = config.SalesTransactionQueueCount() - 1;
for (int i = 0; i < config.CustomerThreads(); i++) {
customer_threads[i] = (
new CustomerThread(config, randomLong(), i, all_products,
all_customers, browsing_queues[bq_no],
sales_queues[sq_no], customer_accumulator,
customer_alloc_accumulator,
customer_garbage_accumulator, staggered_start,
end_time));
if (bq_no-- == 0)
bq_no = config.BrowsingHistoryQueueCount() - 1;
if (sq_no-- == 0)
sq_no = config.SalesTransactionQueueCount() - 1;
customer_threads[i].setStartAndStop(staggered_start, end_time);
staggered_start.garbageFootprint(this);
staggered_start = staggered_start.addRelative(this, customer_stagger);
customer_threads[i].start(); // will wait for first release
staggered_start = staggered_start.addRelative(this, customer_stagger);
}
staggered_start.garbageFootprint(this);
if (customer_stagger != null)
customer_stagger.garbageFootprint(this);

Trace.msg(2, "starting up ServerThreads: ",
Integer.toString(config.ServerThreads()));

server_threads = new ServerThread[config.ServerThreads()];
Util.referenceArray(this,
LifeSpan.NearlyForever, config.ServerThreads());


// startup the server threads
staggered_start = start_time.addMinutes(this, 0);

bq_no = config.BrowsingHistoryQueueCount() - 1;
sq_no = config.SalesTransactionQueueCount() - 1;
for (int i = 0; i < config.ServerThreads(); i++) {
server_threads[i] = (
new ServerThread(config,
randomLong(), i, all_products, all_customers,
browsing_queues[bq_no], sales_queues[sq_no],
server_accumulator, server_alloc_accumulator,
server_garbage_accumulator, staggered_start,
staggered_customer_replacement,
staggered_product_replacement, end_time));
if (bq_no-- == 0)
bq_no = config.BrowsingHistoryQueueCount() - 1;
if (sq_no-- == 0)
sq_no = config.SalesTransactionQueueCount() - 1;
server_threads[i].setStartsAndStop(staggered_start, staggered_customer_replacement, staggered_product_replacement,
end_time);
staggered_start.garbageFootprint(this);
staggered_start = staggered_start.addRelative(this, server_stagger);
staggered_customer_replacement.garbageFootprint(this);
staggered_customer_replacement = (
staggered_customer_replacement
.addRelative(this, customer_replacement_stagger));
staggered_customer_replacement = staggered_customer_replacement.addRelative(this, customer_replacement_stagger);
staggered_product_replacement.garbageFootprint(this);
staggered_product_replacement = (
staggered_product_replacement
.addRelative(this, product_replacement_stagger));
staggered_product_replacement = staggered_product_replacement.addRelative(this, product_replacement_stagger);
server_threads[i].start(); // will wait for first release
}

staggered_start.garbageFootprint(this);
staggered_start = null;

Expand All @@ -277,7 +259,7 @@ public void runExtreme() {

staggered_product_replacement.garbageFootprint(this);
staggered_product_replacement = null;

if (server_stagger != null)
server_stagger.garbageFootprint(this);

Expand All @@ -288,17 +270,15 @@ public void runExtreme() {
if (product_replacement_stagger != null)
product_replacement_stagger.garbageFootprint(this);
product_replacement_stagger = null;

if (config.PhasedUpdates()) {
staggered_start = start_time.addRelative(this, config.PhasedUpdateInterval());
update_thread = new UpdateThread(config, randomLong(), all_products, all_customers, staggered_start, end_time);
update_thread.setStartAndStop(staggered_start, end_time);
update_thread.start(); // will wait for first release
staggered_start.garbageFootprint(this);
staggered_start = null;
} else {
update_thread = null;
}

now = AbsoluteTime.now(this);
if (config.ReportCSV()) {
s = Long.toString(now.microseconds());
Expand All @@ -312,13 +292,15 @@ public void runExtreme() {
Util.abandonEphemeralString(this, s);

if (now.compare(start_time) > 0) {
Configuration.usage("Initialization must complete before start."
+ " Increase InitializationDelay.");
// Does not return.
Report.output("Warning! Consumed more than 4 ms to start each thread.");
s = start_time.toString(this);
Report.output(" Planned to start at: ", s);
s = now.toString(this);
Report.output("Actually starting at: ", s);
}
start_time.garbageFootprint(this);
start_time = null;
end_time.changeLifeSpan(this, LifeSpan.NearlyForever);
now.garbageFootprint(this);
now = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class Configuration {

static final int DefaultPhasedUpdateIntervalSeconds = 60;

static final long DefaultInitializationDelayMillis = 50;
static final long DefaultDurationMinutes = 10;

/*
Expand Down Expand Up @@ -107,7 +106,6 @@ class Configuration {
private String DictionaryFile;
private Words dictionary;

private RelativeTime InitializationDelay;
private RelativeTime SimulationDuration;

private RelativeTime CustomerPeriod;
Expand Down Expand Up @@ -182,12 +180,12 @@ void initialize(ExtrememThread t) {
Polarity.Expand, 17 * Util.SizeOfInt +
2 * Util.SizeOfFloat + 2 * Util.SizeOfBoolean);

// Account for 11 reference fields: args, dictionary,
// DictionaryFile, InitializationDelay, SimulationDuration,
// Account for 10 reference fields: args, dictionary,
// DictionaryFile, SimulationDuration,
// CustomerPeriod, CustomerThinkTime, ServerPeriod, BrowsingExpiration,
// CustomerReplacementPeriod, ProductReplacementPeriod.
log.accumulate(LifeSpan.NearlyForever,
MemoryFlavor.ObjectReference, Polarity.Expand, 11);
MemoryFlavor.ObjectReference, Polarity.Expand, 10);

ResponseTimeMeasurements = DefaultResponseTimeMeasurements;
ReportIndividualThreads = DefaultReportIndividualThreads;
Expand All @@ -211,11 +209,6 @@ void initialize(ExtrememThread t) {
SimulationDuration = new RelativeTime(t, DefaultDurationMinutes * 60, 0);
SimulationDuration.changeLifeSpan(t, LifeSpan.NearlyForever);

InitializationDelay = (
new RelativeTime(t, DefaultInitializationDelayMillis / 1000, (int)
(DefaultInitializationDelayMillis % 1000) * 1000000));
InitializationDelay.changeLifeSpan(t, LifeSpan.NearlyForever);

RelativeTime rt = new RelativeTime(t);
CustomerPeriod = rt.addMinutes(t, DefaultCustomerPeriodMinutes);
CustomerPeriod.changeLifeSpan(t, LifeSpan.NearlyForever);
Expand Down Expand Up @@ -552,9 +545,9 @@ else if ((i + 2 == timeString.length()) &&
u *= 60; // convert minutes to seconds
case 's':
u *= 1000; // convert seconds to ms
case '@':
case '@': // '@' represents ms
break;
case '$':
case '$': // '$' represents no time unit specified
default:
usage("Time suffix must be ms, s, m, h, or d");
}
Expand Down Expand Up @@ -596,9 +589,7 @@ else if ((i + 2 == timeString.length()) &&
}
case 4:
if (keyword.equals("InitializationDelay")) {
InitializationDelay.garbageFootprint(t);
InitializationDelay = new RelativeTime(t, secs, nanos);
InitializationDelay.changeLifeSpan(t, LifeSpan.NearlyForever);
Report.output("Warning. InitializationDelay is deprecated and ignored");
break;
}
case 5:
Expand Down Expand Up @@ -827,10 +818,6 @@ RelativeTime SimulationDuration() {
return SimulationDuration;
}

RelativeTime InitializationDelay() {
return InitializationDelay;
}

RelativeTime CustomerPeriod() {
return CustomerPeriod;
}
Expand Down Expand Up @@ -928,12 +915,6 @@ void dumpCSV(ExtrememThread t) {
Report.output("RandomSeed,", s);
Util.abandonEphemeralString(t, l);

s = Long.toString(InitializationDelay.microseconds());
l = s.length();
Util.ephemeralString(t, l);
Report.output("InitializationDelay,", s);
Util.abandonEphemeralString(t, l);

s = Long.toString(SimulationDuration.microseconds());
l = s.length();
Util.ephemeralString(t, l);
Expand Down Expand Up @@ -1143,11 +1124,6 @@ void dump(ExtrememThread t) {
Report.output(" Seed for random number generation (RandomSeed): ", s);
Util.abandonEphemeralString(t, l);

s = InitializationDelay.toString(t);
l = s.length();
Report.output(" Startup Pause (InitializationDelay): ", s);
Util.abandonEphemeralString(t, l);

s = SimulationDuration.toString(t);
l = s.length();
Report.output(" Duration (SimulationDuration): ", s);
Expand Down Expand Up @@ -1333,16 +1309,15 @@ void garbageFootprint(ExtrememThread t) {
Grow, 17 * Util.SizeOfInt +
2 * Util.SizeOfFloat + 2 * Util.SizeOfBoolean);

// Account for 11 reference fields: args, dictionary, DictionaryFile
// InitializationDelay, SimulationDuration, CustomerPeriod,
// Account for 10 reference fields: args, dictionary, DictionaryFile
// SimulationDuration, CustomerPeriod,
// CustomerThinkTime, ServerPeriod, BrowsingExpiration,
// CustomerReplacementPeriod, ProductReplacementPeriod
garbage.accumulate(LifeSpan.NearlyForever,
MemoryFlavor.ObjectReference, Polarity.Expand, 11);
MemoryFlavor.ObjectReference, Polarity.Expand, 10);

Util.tallyString(t.garbageLog(), LifeSpan.NearlyForever,
Polarity.Expand, DictionaryFile.length());
InitializationDelay.garbageFootprint(t);
SimulationDuration.garbageFootprint(t);
CustomerPeriod.garbageFootprint(t);
CustomerThinkTime.garbageFootprint(t);
Expand Down
Loading

0 comments on commit 7750c6a

Please sign in to comment.