Difference between revisions of "Performance Profiler library"

(What CPU time means with multithreading)
Line 71: Line 71:
 
* [[Managing Memory and CPU Time for large models]]
 
* [[Managing Memory and CPU Time for large models]]
 
* [[Memory Usage Dialog]]
 
* [[Memory Usage Dialog]]
* [[Analytica Libraries and Templates]]
+
* [[Analytica Libraries and Templates]]{{Release|5.0||
 +
* [[Multithreaded evaluation]]}}
  
  
 
<footer>Memory usage and management / {{PAGENAME}} / Analytica Enterprise</footer>
 
<footer>Memory usage and management / {{PAGENAME}} / Analytica Enterprise</footer>

Revision as of 22:52, 9 August 2017





Release:

4.6  •  5.0  •  5.1  •  5.2  •  5.3  •  5.4  •  6.0  •  6.1  •  6.2  •  6.3  •  6.4  •  6.5


The Performance Profiler library shows you the computation time and memory space used by each variable and function.

This feature is available in Analytica Enterprise and Optimizer.

If you have a large model that takes a long time to run or uses a lot of memory, you might want to find out which variables or functions are using the Lion’s share of the time or memory. As experienced programmers know, the results are often a surprise. With the results from the Performance Profiler, you know where to focus your efforts to make the model faster or use less RAM.

First add Performance Profiler.ana from the Libraries folder into your model.

Performance profiler 1.png

Now display the results (table or graph) for the variables whose performance you want to profile. Open the library, and click Performance profiles.

Performance profiler 2.png

This table lists the variables and functions by row, with the class of the object, parent module, Bytes of RAM (random access memory), and CPU msecs (milliseconds of time used by the central processing unit). The last column, msecs w ancestors, shows the CPU milliseconds to compute each variable or function including all its ancestors — i.e., the variables and functions it uses. The Profiler shows all variables and functions that use more than 24 bytes of RAM (the minimum) or take more than 1 millisecond to compute. Use Sort objects by to sort the table by any column.

If you want to inspect a variable or function to see why it’s taking so much time or memory, just click its title in the .Objects index column to open its Object window.

Update profiles

After computing more results, click this button to update the performance profile to reflect the additional time and memory used.

Zero out times

If you want to look at the incremental time used by additional results, or another computation, first click this button to zero out the times already computed.

Understanding memory usage

For complex definitions, it might use much more RAM while it is computing than it needs to cache the final result — the Profiler reports only the latter. The Bytes show the RAM used to store the value of each variable, mid, probabilistic, or both, depending on which it has computed. Typically, an array takes about 12 bytes per number to store. For example, an uncertain dynamic array of numbers, with an index I of 20 elements, Time has 30 elements, and SampleSize = 1000, would use about 20 x 30 x 1000 x12 = 7,200,000 bytes or 7.2 Megabytes. Analytica uses an efficient representation for arrays with many zeroes (sparse arrays) or many repeated values. An array that is an exact or partial copy of another array can share slices. In such cases, it might actually use less memory than it reports.

Understanding computation time

The CPU time listed is the time it took to evaluate the mid and/or prob value of each variable or function, depending on which type of evaluation it did. It is zero if the results computed did not cause evaluation of the variable or function. A variable is usually only computed at most once each for its mid and prob value. Rare exceptions include when the variable is referenced directly or indirectly in a parameter to Whatif or WhatIfall, which might cause multiple evaluations. A function can be called many times. The CPU time reported is the sum over all these evaluations.

Many computations utilize multiple CPU cores simultaneously, which makes the meaning of CPU time potentially ambiguous. CPU time normally refers to the actual number of computing cycles consumed. Your computation might take one minute of wall time, but if much of that time was spent waiting for a database to respond, or the process was competing for CPU resources with other active processes, the CPU time might be much less than real "clock" time. Conversely, a computation that completes in 1 minute using 8 cores effectively uses 8 minutes of CPU time. Performance Profiler's measure of CPU time coincides with the first example, but does not multi-count the concurrent thread usage. Hence will generally be close to wall-time for a multi-core computation that runs continuously. The metric was developed for the usual case where you care about the overall real-time speed of your computation, and not about the total CPU core resources consumed. In other words, you would be happy to have a higher core utilization if it speeds up the overall computation. In the less common case where you care more about total core cycles that real time to completion (e.g., an overtasked server with many simultaneous batch computations in different processes), a more appropriate metric during profiling can be obtained by turning off multithreading by setting MaxModelThreads to 1 and then use the resulting CPU time metric.

Time and virtual memory

Like most 32-bit applications on Windows, Analytica can use up to 3 GB of memory. If your computer doesn’t have that much RAM installed, and it needs more than is available, it can use virtual memory — that is, it saves data onto the hard disk. Since reading and writing a hard disk is usually much slower than RAM, using virtual memory often causes the application to slow down substantially. In this case, finding a way to reduce memory usage below the amount of physical RAM available can speed up the application considerably. Another approach is to install more RAM, up to 4 GB.

Performance profiling attributes and function

The Performance Profiler library uses a function, two attributes, and a command, which are also available for you to write your own functions using memory or time. For an example of how to use them, you can open up the library.

MemoryInUseBy(v)

This function returns the number of bytes in use by the cached result(s) for variable «v» — with the same disclaimer that shared memory can be counted more than once. It includes memory used by mid and prob values if those results have been computed and cached, but it doesn’t force them to be computed if they haven’t been. See MemoryInUseBy().

This function includes these two special read-only attributes:

EvaluationTime

This attribute returns the time in seconds to evaluate its variable or function, not including the time to evaluate any of its inputs.

EvaluationTimeAll

This attribute returns the time in seconds to evaluate its variable or function, including the time to compute any of its inputs that needed to be evaluated (and their inputs, and so on).

ResetElapsedTimings

This command sets these attributes back to zero. Like any command, you can use it in a button script, the Typescript, but not in a regular definition.

Tip
These features, including the Performance Profiler, are only available for Analytica Enterprise, Power Player, and ADE editions.

See Also


Comments


You are not allowed to post comments.