Check-in [94a2cee313]
Overview
Comment:Added script which can be used to generate blocks for a stress test
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 94a2cee313fc4b227484948b30b89db0cb3b42d4483375adf3edd9701a67c7b3
User & Date: rkeene on 2018-08-17 16:21:24
Other Links: manifest | tags
Context
2018-08-17
19:13
Run the same number of concurrent jobs as CPUs check-in: cc3e0b7bd2 user: rkeene tags: trunk
16:21
Added script which can be used to generate blocks for a stress test check-in: 94a2cee313 user: rkeene tags: trunk
13:49
Expose random buffer generation mechanism to the script level check-in: 40140fc849 user: rkeene tags: trunk
Changes

Added examples/stress/stress version [15325924cd].









































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! /usr/bin/env tclsh

## -- INIT
set threadInit {
	package require Thread
	package require sqlite3
	package require nano

	set ::sqlFilename [file join [pwd] blocks.db]
	if {[info exists ::initDB]} {
		file delete -force $::sqlFilename
	}

	sqlite3 db $::sqlFilename

	proc processBlockWorker {orderID block} {
		set block [::nano::block::json::work $block -update]
		db eval {INSERT INTO blocks (orderID, blockJSON) VALUES ($orderID, $block);}
	}
}

set ::initDB true
uplevel #0 $threadInit

set ::numberOfCPUs 2
set iterationCount 1

db eval {
	PRAGMA journal_mode = MEMORY;
	CREATE TABLE blocks (orderID INTEGER PRIMARY KEY, blockJSON TEXT NOT NULL);
}

## -- PROCESSES
set ::jobIDs [list]
set ::threadPool [::tpool::create -minworkers $::numberOfCPUs -maxworkers $::numberOfCPUs -initcmd $::threadInit]
set ::processBlock_orderID -1
proc processBlock {args} {
	updateStatus

	incr ::processBlock_orderID
	
	set jobID [::tpool::post $::threadPool [list processBlockWorker ${::processBlock_orderID} {*}$args]]

	lappend ::jobIDs $jobID

	updateStatus
}

proc updateStatus {} {
	puts -nonewline " -> [llength $::jobIDs] jobs pending         \r"
	flush stdout
}

## -- MAIN
if {[llength $argv] == 0} {
	set seed [::nano::key::newSeed -hex]
	set acct1FrontierHash $::nano::block::zero
	puts stderr "WARNING: Unusable data will be created, use a seed and frontier hash for account-0 to create real data"
} else {
	if {[llength $argv] != 2} {
		error "Usage: stress <seed> <account-0-frontier-hash>"
	}

	set seed [lindex $argv 0]
	set acct1FrontierHash [lindex $argv 1]
}

set key1 [::nano::key::fromSeed $seed 0]
set key2 [::nano::key::fromSeed $seed 1]
set acct1 [::nano::address::fromPrivateKey $key1]
set acct2 [::nano::address::fromPrivateKey $key2]

::nano::account::setFrontier $acct1 $acct1FrontierHash 1 $acct1

for {set blockCount 0} {$blockCount < $iterationCount} {incr blockCount} {
	set block [::nano::account::send $acct1 $acct2 1 $key1]
	processBlock $block
	set hashSend [dict get [::nano::block::dict::fromJSON $block] _blockHash]

	set block [::nano::account::receive $acct2 $hashSend $key2]
	processBlock $block

	set block [::nano::account::send $acct2 $acct1 1 $key2]
	processBlock $block
	set hashSend [dict get [::nano::block::dict::fromJSON $block] _blockHash]

	set block [::nano::account::receive $acct1 $hashSend $key1]
	processBlock $block
}

# Wait for jobs to complete
while {[llength $::jobIDs] > 0} {
	updateStatus

	::tpool::wait $::threadPool $::jobIDs ::jobIDs
}

updateStatus

puts "\nDone !"