Skip to content

Commit

Permalink
Version 1.2.0 ready to tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Paul Argudo committed Apr 18, 2024
1 parent bcff015 commit b6c0b9a
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 77 deletions.
18 changes: 9 additions & 9 deletions bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ You'll find here binaries for your convenience.
- `pgSimload_win.exe` : binary to use in Windows `windows/amd64`

```
$ md5sum pgSimload*
0676f622b8fc213c3a0707b42308b3e0 pgSimload
bee525f38cdbefcd64c58fe0722b26a7 pgSimload_mac
53365de34e4062b70f605aeb98aefe34 pgSimload_static
44a8b6b911fe29576bcb863119c5aa46 pgSimload_win.exe
md5sum pgSimload*
61c63e866796c53606cca227b33cbc9b pgSimload
97ebc3f14eae74b241f154752a6c6b9e pgSimload_mac
cbe9867b32840b6ad72dfa39a35e670b pgSimload_static
42f1028b3964599db54cb2feddd0aac5 pgSimload_win.exe
```

# More information
Expand All @@ -29,13 +29,13 @@ If you're a Linux user, let me warn you that the binary has dependencies:

```
$ ldd bin/pgSimload
linux-vdso.so.1 (0x00007ffcad3a2000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc564800000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc564b18000)
linux-vdso.so.1 (0x00007fff2d7be000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ca096600000)
/lib64/ld-linux-x86-64.so.2 (0x00007ca096949000)
```

Those depedencies would be OK if as an example you're using an up-to-date
Ubuntu Mantic Minautor (aka Ubuntu 23.10) as per January 11th 2024.
Ubuntu Mantic Minautor (aka Ubuntu 23.10) as per April 18th 2024.

But for any other machine without those versions of dependencies, please
download and use instead the binary compiled *statically* for your convenience,
Expand Down
Binary file modified bin/pgSimload
Binary file not shown.
Binary file modified bin/pgSimload_mac
Binary file not shown.
Binary file modified bin/pgSimload_static
Binary file not shown.
Binary file modified bin/pgSimload_win.exe
Binary file not shown.
19 changes: 17 additions & 2 deletions doc/01_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ $ sh build.sh
## DEB and RPM packages

We've started tests to build those packages but at the moment, the work hasn't
finish yet. Those packages will be available soon.
finish yet. But do you really need this, since pgSimload is a standalone
binary ?

# Usages

Expand All @@ -68,6 +69,10 @@ This tool can be used in different infrastructures:
This tool as different usages, and you probably think of some that I haven't
listed here:

- just initiate a plain `select 1`, a `select count(*) from...`, whatever
you find usefull. But pgSimload won't get you results back from those
executions

- insert dummy data (mostly randomly if you know about, mostly,
`generate_series()` and `random()` PostgreSQL functions) any DB with the
schema of your choice and the SQL script of your choice
Expand Down Expand Up @@ -103,7 +108,7 @@ listed here:
write work on a PostgreSQL server (standalone or the primary of a
PostgreSQL cluster with a(some) replica(s).

- as per version 1.1.0, the SQL-Loop mode execution can be limitated to:
- the SQL-Loop mode execution can be limitated to:

- a number of loop exections you define thanks to the `-loops <int64>`
parameter and/or
Expand All @@ -115,6 +120,16 @@ listed here:
- if both parameters are used at the same time, the SQL-Loop will end
whenever one or the other condition is satisfied

- the rate of the iterations can be slowed down since version 1.2.0 thanks
to the `-sleep duration` parameter, where a duration is expressed the
same way `-time duration` is (see upper). If this parameter is set to
anything else that 0, pgSimload will sleep for that amount of time.
This is usefull if you want to slow down the SQL-Loop process. It also
avoid the user to manually add like a `select pg_sleep(1);` at the end
of the `SQL script` used with `-script`. So it's faster to test
different values of "sleeping" by recalling the command line and
changing the value there instead of editing that SQL script...

- test failovers, or what happens when a DB is down: pgSimLoad handles those
errors. Give it a try: simply shuting down your PostgreSQL server while it
runs... You'll see it throwing errors, then restarting to load once the
Expand Down
38 changes: 30 additions & 8 deletions doc/02_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,41 @@ No creation of tables and others are needed, so there's no need to call for
`-create <create.json>` or such. pgSimload accepts the omission of parameter
`-create`.

Here's something for the user to understand:

- `script.one_liner.sql` contains a simple "select 1;" with a sleep(1)
**on the same line**, where

- `script.two_liner.sql` contains the same, but each command on one line.
`script.sql` contains a simple "select 1;". There's also a comment starting
with `--`, like in ... plain SQL. So that means this file is just the SQL
script you want it to be. Simple as that.

Once pgSimload has been compiled **and** the `config.json` adapted to suit
your needs, this could be used as simple as:

```code
$ pgSimload -config config.json -script script.one_liner.sql
$ pgSimload -config config.json -script script.two_liner.sql
$ pgSimload -config config.json -script script.sql
```

You can throtle it down asking pgSimload to wait for 1 second and a half like
this:

```code
$ pgSimload -config config.json -script script.sql -sleep 1s500ms
```

If you want to limit the number of loops, you can do that as simply as

```code
$ pgSimload -config config.json -script script.sql -loops 10
```

Alternatively, you can limit the execution time, setting a duration:

```code
$ pgSimload -config config.json -script script.sql -time 5s
```
You can do both at the same time. Whichever happens first will
break the SQL-Loop:

```code
$ pgSimload -config config.json -script script.sql -time 1s -loops 20
$ pgSimload -config config.json -script script.sql -time 10s -loops 20
```

## `examples/PG_15_Merge_command/`
Expand Down
25 changes: 25 additions & 0 deletions doc/03_overview_of_flags_and_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ All flags are optional and intended to run alone.
| `session_parameters` | | **X** | JSON file | Sets special session configuration parameters |
| `loops` | | **X** | integer | Sets the number of loops to execute before exiting |
| `time` | | **X** | duration | Sets the total execution time before exiting |
| `sleep` | | **X** | duration | Sets a sleep duration between 2 iterations of the SQL-Loop |


## Patroni-Watcher mode : parameters
Expand Down Expand Up @@ -312,6 +313,30 @@ Total exec time : 10.104s
This parameter can be used in conjuction with the `-loops` parameter seen in
the previous paragraph. Whichever is satisfied first will end the SQL-Loop.

### **sleep** (duration) [OPTIONAL]

This parameter was added in version 1.2.0.

It allows the user to actually throttle down the execution in SQL-Loop mode.

A pause of the `sleep` duration will be added between each iteration of the
execution of the SQL script.

That duration is expressed the very same way the `time` parameter is (see
previous paragraph).

Note that when `sleep` and `time` are used together, it can cause side effects
on the total desired execution time, as an example:

- the script is a plain "select 1;" that goes ultra fast (time to exec is
close to 0 seconds)
- `time` is set to `10s`
- `sleep` is set to `4s`
- the total execution time *won't be* 10s, but rather 12s, because on the
3rd execution at 8s, the pause will last 4s, leading to 12s overall...

Just bare that in mind when creating your tests use cases, etc.

## Patroni-Watcher mode flag and parameters

To use have pgSimload act as a Patroni-Watcher tool in a side terminal, all
Expand Down
31 changes: 31 additions & 0 deletions doc/04_release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Release notes

## Version 1.2.0 (April 18th 2024)

### Major changes

- Added a new parameter to pgSimload command line to be used in SQL-Loop mode:

- `-sleep time.Duration` adds a sleep time between 2 iterations (executions)
of the `-script script.sql` (or whatever it's name).

- The interest of this parameter is double:

- it allows to throttle down the execution in SQL-Loop mode if this one is
"going too fast" and

- it avoids the user to add a line like `select pg_sleep(1);` at the end
of the `script.sql`.

- Actually it corrects indirectly the previous behaviour when that `select
pg_sleep(n);` was used previously in `script.sql` around the count of
statements executed. This one was only updated once the *whole* script was
executed, including the possible `select pg_sleep(n);` at the end.

- documentation update to describe the new `-loops` and `-time` parameters to
be used in SQL-Loop mode

### Minor changes

- updated `examples/simple` examples and README file

### Minor changes

## Version 1.1.0 (January 20th 2024)

### Major changes
Expand Down
Binary file modified doc/pgSimload.doc.pdf
Binary file not shown.
29 changes: 16 additions & 13 deletions examples/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,40 @@ No creation of tables and others are needed, so there's no need to call for
`-create <create.json>` or such. pgSimload accepts the omission of parameter
`-create`.

This is the most simple example, and here you learn how you can eventually add
a wait in your loops,:
`script.sql` contains a simple "select 1;". There's also a comment starting
with `--`, like in ... plain SQL. So that means this file is just the SQL
script you want it to be. Simple as that.

- `script.one.sql` contains a simple "select 1;"

- `script.two.sql` contains the same, but with a sleep(1) added

Once pgSimload has been compiled **and** the `config.json` adapted to suit
your needs, this could be used as simple as:

```code
$ pgSimload -config config.json -script script.one.sql
$ pgSimload -config config.json -script script.two.sql
$ pgSimload -config config.json -script script.sql
```

You can throtle it down asking pgSimload to wait for 1 second and a half like
this:

```code
$ pgSimload -config config.json -script script.sql -sleep 1s500ms
```

If you want to limit the number of loops, you can do that as simply as

```code
$ pgSimload -config config.json -script script.one.sql -loops 10
$ pgSimload -config config.json -script script.sql -loops 10
```

Alternatively, you can limit the execution time, setting a duration:

```code
$ pgSimload -config config.json -script script.one.sql -time 5s
$ pgSimload -config config.json -script script.sql -time 5s
```

And finally, you can do both at the same time. Whichever happens first will
You can do both at the same time. Whichever happens first will
break the SQL-Loop:

```code
$ pgSimload -config config.json -script script.one.sql -time 1s -loops 20
$ pgSimload -config config.json -script script.one.sql -time 10s -loops 20
$ pgSimload -config config.json -script script.sql -time 1s -loops 20
$ pgSimload -config config.json -script script.sql -time 10s -loops 20
```
File renamed without changes.
4 changes: 0 additions & 4 deletions examples/simple/script.two.sql

This file was deleted.

8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ require (
github.com/MakeNowJust/heredoc v1.0.0
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203
github.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3
github.com/jackc/pgx/v5 v5.5.2
golang.org/x/crypto v0.18.0
github.com/jackc/pgx/v5 v5.5.5
golang.org/x/crypto v0.22.0
)

require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
)

require golang.org/x/sys v0.16.0 // indirect
require golang.org/x/sys v0.19.0 // indirect
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA=
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.5.2 h1:iLlpgp4Cp/gC9Xuscl7lFL1PhhW+ZLtXZcrfCt4C3tA=
github.com/jackc/pgx/v5 v5.5.2/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
31 changes: 3 additions & 28 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ var (
scriptfilename stringFlag
exec_loops int64 = 0
exec_time time.Duration
sleep_time time.Duration

Version = "pgSimLoad v.1.1.0 - January 20th 2024"
Version = "pgSimLoad v.1.2.0 - April 18th 2024"

License = heredoc.Doc(`
**The PostgreSQL License**
Expand Down Expand Up @@ -92,33 +93,6 @@ func (sf *stringFlag) String() string {
return sf.value
}

/*********
//Int64 Flags
type int64Flag struct {
set bool
value int64
}
func (int64f *int64Flag) Set(x int64) error {
int64f.value = x
int64f.set = true
return nil
}
//func (int64f *int64Flag) String() string {
// return string(int64f.value)
//}
*********/


/******
// Function to print out on screen error messages (in red)
func printerrormsg (message string) {
}
*******/

// Function to exit(1) the program putting in red the error message
func exit1(message string, errcode error) {
fmt.Print(string(colorRed))
Expand All @@ -141,6 +115,7 @@ func init() {
flag.Var(&gathergucsfilename , "create_gucs_template", "outputs to that JSON filename")
flag.Int64Var(&exec_loops, "loops", 0, "number of SQL-Loop to execute")
flag.DurationVar(&exec_time, "time" , 0, "duration of SQL-Loop execution")
flag.DurationVar(&sleep_time, "sleep", 0, "sleep duration between iterations in SQL-Loop")
}

//function to check flags passed with --flag value
Expand Down
11 changes: 10 additions & 1 deletion sqlloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ func do_sqlloop(pgManager *PGManager) {
exit1(message,nil)
} else {
fmt.Println()
fmt.Printf("Now entering the main loop, executing script %q\n",scriptfilename.value)

if sleep_time > 0 {
fmt.Printf("Now entering the main loop, executing script %q each %q\n",scriptfilename.value, sleep_time)
} else {
fmt.Printf("Now entering the main loop, executing script %q as fast as possible\n",scriptfilename.value)
}

if exec_loops !=0 || exec_time !=0 {
fmt.Printf("\nNumber of loops will be limited:\n")
Expand Down Expand Up @@ -306,6 +311,10 @@ loop:
break loop;
}

if sleep_time > 0 {
time.Sleep(sleep_time)
}

}
}
}
Expand Down

0 comments on commit b6c0b9a

Please sign in to comment.