PyDQ: PDQ in Python (original) (raw)
PyDQ: PDQ in Python
This page was last updated on Aug 31, 2008
Contents
1 Release Information
2 Installing PyDQ
3 Related Python Tools
3.1 SciPy
3.2 NumPy
3.3 SimPy
4 PyDQ Examples
4.1 Single queueing facility
4.2 Communications network
5 Feedback
1 Release Information
Dateline: Fri, Apr 20, 2007
This page has been updated to include more python-specific examples, as well as showing how to use PyDQ with other python packages, e.g., NumPy (see Sections 3.2 and 4.2). The online PDQ Manual also contains PyDQ definitions and examples. The Pythonversion of PDQis included as part of the current PDQ release. Making the PDQ C library available to the Python interpreter was the handy work of Peter Harding (in Australia) using the SWIGwrapper facility.
2 Installing PyDQ
Download the current PDQ distribution. The installation and setup files are located in the /pdq/python/ directory. The two setup options are:
- Run the Makeall script at the top-level directory:
shell> ./Makeall - Build manually in the python directory:
shell> cd python
shell> make
shell> ./test.py See the online PDQ Manualfor a synopsis of PyDQ functions and their usage.
3 Related Python Tools
3.1 SciPy
For those of you who are interested in HPC and scientific computing applications, there isSciPywhich includes python modules for graphics and plotting, optimization, integration, special functions, signal and image processing, genetic algorithms, ODE solvers, etc.
3.2 NumPy
NumPy (Numerical Python) provides sophisticated array facilities to the Python language. NumPy is the most recent and most actively supported package, and replaces the older Numeric. It is documented as part of SciPy (Section 3.1).
3.3 SimPy
SimPy(Simulation in Python) is such an open-source, event-based simulator which includes the ability to plot results. It can be used to simulate the same kind of queueing network models that can be solved in PyDQ. SimPy can be thought of as a natural adjunct for PyDQ and vice versa.
4 PyDQ Examples
PyDQ examples can be found in the /pdq/examples/misc and /pdq/examples/ppq_1998 directories.
4.1 Single queueing facility
Consider the checkout-aisle in a grocery store. It consists of a single server (the cashier) and customers arrive at the checkout to have their groceries rung up. Only one customer can be in service at a time. The other customers have to form a single waiting line. The whole facility acts like a queue. We can make a PyDQ model of such a checkout, where the mean service time is S = 1.0 minute and customers arrive at a rate of 3 customers every 4 minutes or λ = 0.75 customers per minute. You can read the commented PyDQ code online. For such a simple queue, we can manually calculate some performance measures:
Cashier utilization:
ρ = λS = 0.75 or 75% busy
Residence time:
R = S / (1 − ρ) = 4 minutes
Queue length:
Q = λR = 3 customers
Waiting line:
L = Q − ρ = 2.25 customers
We can now compare these calculations with those generated by the PyDQ model in the corresponding report.
4.2 Communications network
Consider the following communications network where the global call rate is λ = 0.50:
The SimPy simulation codeis typically longer and more complex than the corresponding PyDQ code. In this case, the traffic equations are solved within the same PyDQ program using the NumPy matrix solver from SciPy (see Section 3.2). The specific steps involved are:
- Use the routing probabilities in the diagram to write down the traffic equations:
- Use the NumPy solver to calculate the internal workflows: λ1, λ2, λ3
- Use these values to calculate the visit ratios: v1 = λ1/λ, v2 = λ2/λ, v3 = λ3/λ
- We are told the router service times: S1 = 1.0, S2 = 2.0, S3 = 1.0,
- Use the visit ratios to define the router service demands: D1 = v1 S1, D2 = v2 S2, D3 = v3 S3
- Use these service demands to parameterize the pdq.SetDemand() function in PyDQ
- Call pdq.Solve(pdq.CANON) Running this PyDQ modelproduces this report. The PyDQ source ../examples/misc/jackpdq2.py for this model can be found in the PDQ distribution. The following table provides some comparative statistics between SimPy and PyDQ.
Statistic | SimPy | PyDQ |
---|---|---|
Avg. queue length at Comp1 | 1.6297 | 1.5625 |
Avg. queue length at Comp2 | 1.6192 | 1.5625 |
Avg. queue length at Comp3 | 1.1724 | 1.2162 |
Avg. number in the system | 4.4213 | 4.3412 |
Average response time | 8.8639 | 8.6824 |
Average service time | 1.1994 | 1.1994 |
Average throughput | 0.4983 | 0.5000 |
Total jobs simulated | 9966 | N/A |
Total simulation time | 20000.00 | N/A |
real time | 67.56 | 0.20 |
user time | 20.32 | 0.07 |
sys time | 1.96 | 0.02 |
Lines of code in the model | 197 | 75 |
Note that PyDQ calculates exact values based on the assumption that the traffic flow has reached steady-state equilibrium. This means essentially that measurements of both input and outputperformance metrics have been sampled long enough that the statistical means (i.e., averages) are meaningful. This begs the question, how long is long enough? Since PyDQ is an analytic solver and not a simulator, the question is moot because the system is solved assuming it is in steady state. SimPy, however, and any other kind of simulator for that matter (including load-test platforms) must be run "long enough" to produce statistical outputs that correspond to steady state. Insufficient runtime can produce inaccurate results. One way to gain confidence that the simulation runtime is sufficient, is to compare its outputs with those computed by PyQ. The table above shows example values that compare favorably with PyDQ, but trade-off is that SimPy had to run for about350 times longer than PyDQ.
5 Feedback
New versions of PDQ are released periodically. Please fill out this formif you would like to notified by email.
File translated from TEX by TTH, version 3.38.
On 31 Aug 2008, 08:41.