Thursday, 3 December 2026

To put some load on Oracle26ai - I use these scripts.

 TL;DR: There are many good load generaters or benchmark tools out there. But I still use my own, very very simple, scripts a lot.


Image: Piling loads of stuff onto a moped. I will pile some load on a database, just to see how it reacts under stress.


Background: Why do I have load-generating scripts ?

The Agile-DevOps adage is to move-fast and break things (and me? well, I can at least "break things").

I have a few scripts and tricks to make an RDBMS (mostly, Oracle) work hard. Why? Sometime you want to know how fast the underlying CPU is, sometimes you want to get a feel for the (overloaded, stresssed) IO channels, sometimes, you want the server to "explode with PGA". But mostly, I just want to verify that I am looking at the relevant information.

There are lots of load-generator and "benchmarks" out there, some of them as old as my own scripts, from before y2k. I'll mention a few:

SLOB, from Kevin Closson. Simple, Elegant. Will stress the IO system by using the database. Requires a very small cache-setting.

Orion and its successor, Calibrate_IO (link to Oracle-Base, as Tim always provides easy-runnable examples). Orion runs "outside" of the RDBMS. Calibrate_io needs you to connect to the CDB as sys, and it is vaguely licensed. I would not risk that on a cstmr in a potentially audited environment. Otherwise: Quite Useful, as it spits out numbers straight away and saves them in a view.

HammerDB (formerly HamerORA by Steve Shaw).Very Useful. And still actively maintained. But it takes time + resources to set up.

Swingbench by Dominic Giles, Possibly the Golden Standard for testing Oracle RDBMS. But still takes some setup-activity.

That list above is just to show I am not ignorant. Nor am I a complete luddite. But there are always several reasons why those above do not fit into an existing cstmr/production situation. Different Stories, some other time.

All this intro to confess that I still have my own very basic, primitive, testing-scripts. Since way back before y2k even. Although they have been modified a lot over time, the main principles have remained: Simple, Easy to run, easy to understand, easy to adapt.


Main usage: Casual Confirmation of the Correct Procedures.

The scripts presented below are by no means a proper benchmark, and should not be use in systematic evaluation of capacity or performance of systems. They are purely for "first look".

The main reason I use these are to "confirm" what we are looking at. Whenever I get to observe a system via OEM, AWR, sar, iostat, taskmgr, statspack, cloudwatch, or some some other tool, I want to double-check what I am looking at. I want to establish that I am looking at the correct system and the relevant information. 

[small rant] Probably 50% of times I got an AWR or sp-report, or screenshot of some observation-tool mailed, or when I was given a screen or prompt to "look at the system", that information was from the Wrong Database or the wrong time-interval, or on the wrong system. Hence, others and myself still, often, make the mistake of looking at the wrong data. This is why my checklist includes a verification for database-names, service-names, and timestamps in the information. We have to always firmly establish that this is indeed the "problem system" that has to be investigated. [/rant over].

At this point, I am reminded of a legendary cult-movie-quote from the 90s.. 

If you havn't seen the tremors-movies yet, start with the original from 1990.

Anyway, by creating a few minutes of CPU or IO-load on a system, you can show to yourself and your co-workers that the observation-system you are using is indeed looking at the correct system, and at the correct time. Furthermore, you are ensuring that you or your local colleagues can connect and query exactly that system. And you also get a first impression on how it will react to additional load.

Hence one of my reasons to keep these scripts around.


Load up the CPUs, and how many CPUs do we actually have...?

My first script is spin.sql. It is meant to occupy 1 CPU or one Thread, for a given number of seconds. Running it looks like this:

It takes 1 argument, the nr of seconds you want the spin to run. And the output of loops/sec will give you an idea of how fast the underlying CPU will serve this RDBMS. 

In the performance-screen of OEM (and other similar tools) this will show up as Green. Every running instance of this script will cause a horizontal green area, representing 1 CPU.

The actual script is a PL/SQL block that does ... Nothing. Check for yourself with the link to script. It runs a loop until time is up. If the PL/SQL processor ever becomes Really Clever it may just refuse to do anyting, or it may decide that it can replace the loop by a sleep and report out a random number at the end. That would be a good joke by Oracle on us actually.

Tip: try running more spin-sessions and observe your (sysstat) sar-output, or a similar metric. Then increase the nr of spins to your cpu_count parameter, or even to the actual nr of CPUs provisioned for that machine. See how it reacts.

[Anecdote:] I cherish this script. It was particularly fun back in 2007, at a customer who had purchased a brand-new machine with 24 CPUs (that was still a sizeable machine, and expen$ive hardware back then). We tried running spin.sql with 4, 8, 12, 16, ... many sessions spinning on the first database on that machine. The sar-output showed that idle-time didnt decrease as much as we had anticipated. The sysadmin went back to investigate and got all excited when he found out that the actual box contained more (activated-) CPUs than the 24 we paid for. And it was able to use them properly. We informed our teamleader, showed him the proof and he then told us to not speak too much about that. That machine went on to contain 100+ databases for dev/test/acc/regress/perf... (The sysadmin was called Martin, and he was once photographed by the google-camera while standing at "smokers corner" outside the office. He is still visible on the old streetview. Good Memories..) [/anecdote]


Logical IO - Cartesian product to provoke (mostly) CPU-ticks.

For a while I used some LIO-scripts as well. But LIO is actually (mostly) just CPU-work. And if you just want to see your CPU spin, you can do even more simple than my script, just give the RDBMS a carthesian product on two large sets. I could invite you to copy/past the following, and sit back:

SQL > select count (*) from all_source, all_tab_columns ;

That will take a bit of time and is guaranteed to be 99% CPU effort. If you want longer runing SQL, just add tables or views and leave out any join-conditions.

The problem with queries like this is that they can and will run for an undetermined time. Hence. you often end up doing a kill-session, a Control-C, or a kill-minus-nine. All of which is un-elegant and sometimes messy. Hence I reverted to the original spin.sql which attempts to do "purely CPU work".

But thought I'd put down this shortcut to an easy-to-type carthesian product anyway. Just in case someone is in a real hurry.


Some real (Physical) disk_reads, hoping for actual IO from disk.

Yaya yaaah, I know, "hope is not a strategy".. and I full well realize the shortcomings of my script here. I still present it. This script is best used on non-Exadata systems. But I actually also use it on Exadata systems sometimes, even just to compliment spin.sql with a more diverse load. It has a few "features".

The script was built to try and provoke disk-reads, showing up as blue-time in the OEM screen, and it is called spin_pio.sql:

Notice how I ask it to spin for 45sec, but it actually spends 51sec? 

This script does a union-query of All_tables and All_views, and will try to count(*)  all of them, until it hits the specified time from arg1 (the &1 for the SQL*Plus and SQLcl folks).

However this script also could easily go "runaway" when it was busy doing a select-full-count-star query on a large table. Hence the risk of this script is (was) that it would run for many minutes or more past its intended time when it hit large tables. For that reasons, I had to build in a condition for "rownum <= some_number".

Another quirk when trying to run multiple of those spin_pio script was that the 2nd and subsequent runs would hit cache, rather than disk-reads. To this end I had a clone-script that would inverse the order of the objects it would query. 

I did not build in the "flush buffer_cache", because that could ruin the day if anyone ran it on a Production system. But you can still do that flush by hand if you want to.

At some point, I also built in a /* watermark */ in the select-queries, which allowed me to follow it by looking at V$SQLAREA and to point out the queries to others if they were interested. Here is a sample from a running database:

Can you spot the watermark in the selects? It "displays" the nr of loops done by that script, and it contains the start time of that particular SQL. Just another one of my ways to keep track of what is going on.

And from re-visiting this script to write about it, a lot of the old ideas come back: I should really use v$mystats and v$events to count + time the IO caused by the session that is reading. And I could use it as an informal benchmark, like I did for the loop-count on CPU speed.

But the problems with generating "Disk Reads" are multiple. Let me mention two of them:

. Problem a) Caching. The buffer-cache will try to hold all data, and prevent disk reads. And if not the buffer-cache, there is also caching at the levels of filers or storage arrays. This can lead to the following situation:

Notice how two runs of 10sec each lead to a very different nr of "executes" ? On the second run, the nr is much higher, notably due to Caching effect, possibly other factors as well.

. Problem b) Engineered systems. Exadata will tell you "cell physical IO...", in which case you may be reading from disk, or from cell-cache, or some "smart cache" out there.

Note: My spin_pio.sql  script pre-dates Exadata by at least 10yrs, and I never had the need to really dig into cell-IO. Hence, I still fail at generating Truly Physical Reads in an Exadata system. But I can try to scan as many blocks as I can. 

Yes, this particular script is in for a serious overhaul to create an Exadata version. but in all the years, I have not yet had the need to measure or "benchmark" an Exadata. Exa-machines are simply good at processing a lot of data, and I also found that most Exadata machines are silently running "small" databases which easily fit in SGA or cell-based cache memory.


About Transactions and Redo-generation - a Teaser.

[Edited - some of this content got removed or postponed] 

I have experimented with similar spin-scripts to generate excessive redo (and log-switches) and to generate an excessive nr of commits/second. 

This can lead to a wait-event-graph looking like this:

The result of a spin_redo of 60sec. There is a lot to investigate here, and a long list of caveats on redo-files, db-parameters, server-parameters and more angles to discuss than I can currently fit in a readable paragraph.

Suffice to say that commit-frequency, commit-parameters, tx-size and redo-generation can really make your wait-event-screen look colorful (green, blue, red, brown ... ). But those scripts are both more complicated and not yet as mature as the ones discussed so far. Hence I'm skipping that for now. Maybe later.

And a similar reasoning is valid for "spin_pga", where I tried to (over)load the PGA with a number of processes and data to try and "break things". Later.

[/edited]


Inspiration to improve (but beware of complexity!)

You can Always Improve code, scripts, systems. We used to call it CTD (link to Tim, 2009...). 

Just from writing this blogpost and revisiting the scripts, I already got some old ideas surfacing and some new ideas popping up. Here is a list of ideas for myself, or anyone who wants to hack the code.

Idea 1) More numbers reporting. Print out more info on looping and timings. For example, the PIO script can also count total-row-processed. Looking at generally helps. Over time you will get a feeling for "how fast" a system or its components are. Like I did from the loop-count of the original spin.sql for CPU speed.

Idea 2) Keep Results. Always spool results, preferably to a file name : spin_cpu_<Service_name>_yyyymmdd_hh24mi.lst. And (idea 2.1) possibly in a format that you can import easily into some repostitory with benchmarks (e.g. generate easy-loadable csv-data, or even insert-stmnts).

Idea 3) Add some Exa-specific metrics. The scripts work OK on and Exadata, but I would like to provoke some of the specific Exa-events.

Idea 4) Add arg2, arg3 to the scripts. Notably for spin_io: add the max-rows, arg2, as a parameter. For "Larger" systems, the default is nowadays too small. Simlarly, the looping could read the tables in reverse-alphabetical order, arg3. This would prevent multiple-scripts to read the same, cached, data shortly after eachother.

Idea 5) Flush the buffer-cache. Either as a cmd-option (arg<n>, or by default. This option has been available since at least v11, or even earlier. I think there were some less-document alter-system-events even before that.

As usual, the problems with such improvements are that they complicate the scripts (simple-oracle-dba, remember), and they would require me to "think before I run". SQL*Plus never was friendly in processing &1, &2, etc, and substituting specifics for defaults requires more script stuff. I am not only Simple, I am also lazy.


Conclusion: No shame in building and running your own scripts.

For this blogpost: I is mostly intended as notes-for-myself, and possibly, hopefully, as Inspiration for the reader to "Build your Own".

My scripts are Very Primitive compared to the exising well known tools. And mine will only be of limited use for others. But I am still glad I kept them around. They still serve me.

If you ever come across situations where you need something like these scripts, for a Quick-Look or a Quick-Assessment, feel free to copy them. But you can also, always easily write.your own and learn/discover things in the process.


Other Takeways: Explaining = Learning. And some topics have to wait.

You will always have a better understanding of what you do when you "build and run your own". And as an aside, by "outing" my scripts via this blogpost, I had to re-visit them. And some of them have just received some overdue TLC. 

Also, the spinning and (stress-)testing of redo, commits and PGA will have to wait for another time.

Lastly, maybe a tip for any future #JOELKALLMANDAY writing: You only Really learn stuff if you have to explain it to someone else.

-- -- -- -- -- End of this Blogpost - for now -- -- -- -- -- 

Appendix: links to scripts.

spin.sql  <nr_seconds> :  Utilize one CPU for nr_seconds

spin_pio.sql  <nr_seconds> : attempt to read from disk, for nr_seconds.

-- -- -- -- -- End of this Blogpost - for Real -- -- -- -- --