Skip to content

Commit ebd61b1

Browse files
committed
Slow down the writing from the client
1 parent dec5e32 commit ebd61b1

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

Diff for: fabfile.py

+23-28
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def dyn_server_role():
4242
from collections import defaultdict
4343
env.timings = defaultdict(list)
4444

45-
NUM_MACHINES = 10
45+
NUM_MACHINES = 8
4646

4747
@runs_once
4848
def ec2start():
@@ -74,7 +74,7 @@ def ec2stop():
7474

7575
@roles("servers")
7676
def time():
77-
with cd('/home/ubuntu/projects/rscoin/src'):
77+
with cd('/home/ubuntu/projects/rscoin'):
7878
x = run('py.test-2.7 -s -k "full_client"') + "\n\n"
7979
x += run('py.test-2.7 -s -k "timing"')
8080

@@ -93,15 +93,13 @@ def null():
9393

9494
@roles("servers","clients")
9595
def gitpull():
96-
with cd('/home/ubuntu/projects/rscoin/src'):
97-
# run('git commit -m "merge" -a')
96+
with cd('/home/ubuntu/projects/rscoin'):
9897
run('git pull')
9998

10099
@roles("servers", "clients")
101100
@parallel
102101
def gitall():
103-
with cd('/home/ubuntu/projects/rscoin/src'):
104-
# run('git commit -m "merge" -a')
102+
with cd('/home/ubuntu/projects/rscoin'):
105103
run('git pull')
106104

107105

@@ -112,20 +110,20 @@ def host_type():
112110
@roles("servers")
113111
@parallel
114112
def start():
115-
with cd('/home/ubuntu/projects/rscoin/src'):
113+
with cd('/home/ubuntu/projects/rscoin'):
116114
run('twistd -y rscserver.tac.py')
117115

118116
@roles("servers")
119117
@parallel
120118
def clean():
121-
with cd('/home/ubuntu/projects/rscoin/src'):
119+
with cd('/home/ubuntu/projects/rscoin'):
122120
run('rm log-*')
123121
run('rm keys-*')
124122

125123
@roles("servers", "clients")
126124
@parallel
127125
def stop():
128-
with cd('/home/ubuntu/projects/rscoin/src'):
126+
with cd('/home/ubuntu/projects/rscoin'):
129127
run('kill `cat twistd.pid`')
130128

131129
@roles("servers")
@@ -138,7 +136,7 @@ def keys():
138136
env["rsdir"] = {"special": pid, "directory": []}
139137

140138
[_, host] = env.host_string.split("@")
141-
with cd('/home/ubuntu/projects/rscoin/src'):
139+
with cd('/home/ubuntu/projects/rscoin'):
142140
run('touch secret.key')
143141
run('rm secret.key')
144142
result = run('python derivekey.py --store')
@@ -154,37 +152,34 @@ def keys():
154152
@roles("servers","clients")
155153
@parallel
156154
def loaddir():
157-
with cd('/home/ubuntu/projects/rscoin/src'):
155+
with cd('/home/ubuntu/projects/rscoin'):
158156
put('directory.conf', 'directory.conf')
159157

160158
@roles("clients")
161159
@parallel
162160
def loadsecret():
163-
with cd('/home/ubuntu/projects/rscoin/src'):
161+
with cd('/home/ubuntu/projects/rscoin'):
164162
put('secret.key', 'secret.key')
165163

166164

167165
@roles("servers","clients")
168166
@parallel
169167
def passcache():
170-
put('known_hosts', '~/.ssh/known_hosts')
171-
with cd('/home/ubuntu/projects/rscoin/.git'):
172-
sudo('touch ~/.ssh/id_rsa && rm ~/.ssh/id_rsa')
173-
put('~/.ssh/id_rsa', '~/.ssh/id_rsa')
174-
run('chmod 600 ~/.ssh/id_rsa')
175-
put('../.git/config', 'config')
176-
177-
with cd('/home/ubuntu/projects/rscoin/src'):
168+
# Delete old folder and make a new one
169+
sudo( 'rm -rf /home/ubuntu/projects/rscoin')
170+
171+
with cd('/home/ubuntu/projects'):
178172
sudo('pip install petlib --upgrade')
179-
run("git pull")
173+
run("git clone https://github.com/gdanezis/rscoin.git")
180174

181175
@runs_once
182176
def init():
183177
local("grep rsa ~/.ssh/known_hosts > known_hosts")
178+
local("python derivekey.py --store")
184179
execute(passcache)
185180

186181
def runcollect():
187-
with cd('/home/ubuntu/projects/rscoin/src'):
182+
with cd('/home/ubuntu/projects/rscoin'):
188183
run("collectl -f LOGFILE -D")
189184
num = run("ps -A | grep collect")
190185
print re.findall("[0-9]+", num)[0]
@@ -217,7 +212,7 @@ def experiment1run():
217212
# local('sudo sysctl -w net.ipv4.ip_local_port_range="500 65535"')
218213
# local("sudo echo 20000500 > /proc/sys/fs/nr_open")
219214
# local('sudo sh -c "ulimit -n 1048576"')
220-
with cd('/home/ubuntu/projects/rscoin/src'):
215+
with cd('/home/ubuntu/projects/rscoin'):
221216
run("python simscript.py %s payments.txt" % env.messages)
222217
run("rm -rf %s" % env.expname)
223218
run("mkdir %s" % env.expname)
@@ -227,33 +222,33 @@ def experiment1run():
227222
@roles("clients")
228223
@parallel
229224
def experiment1pre():
230-
with cd('/home/ubuntu/projects/rscoin/src'):
225+
with cd('/home/ubuntu/projects/rscoin'):
231226
run("./rsc.py --play payments.txt-r1 > %s/r1-times.txt" % env.expname)
232227

233228

234229
@roles("clients")
235230
@parallel
236231
def experiment1actual():
237-
with cd('/home/ubuntu/projects/rscoin/src'):
232+
with cd('/home/ubuntu/projects/rscoin'):
238233
run("./rsc.py --play payments.txt-r2 --conn 20 > %s/r2-times.txt" % env.expname)
239234

240235

241236
@roles("clients")
242237
def experiment1collect():
243238
# run("ls experiment1/*")
244-
with cd('/home/ubuntu/projects/rscoin/src/%s' % env.expname):
239+
with cd('/home/ubuntu/projects/rscoin/%s' % env.expname):
245240
get('issue-times.txt', '%s/%s-issue-times.txt' % (env.expname, env.host))
246241

247242
with lcd(env.expname):
248243
local("cat %s-issue-times.txt >> issue-times.txt" % env.host)
249244

250-
with cd('/home/ubuntu/projects/rscoin/src/%s' % env.expname):
245+
with cd('/home/ubuntu/projects/rscoin/%s' % env.expname):
251246
get('r1-times.txt', '%s/%s-r1-times.txt' % (env.expname, env.host))
252247

253248
with lcd(env.expname):
254249
local("cat %s-r1-times.txt >> r1-times.txt" % env.host)
255250

256-
with cd('/home/ubuntu/projects/rscoin/src/%s' % env.expname):
251+
with cd('/home/ubuntu/projects/rscoin/%s' % env.expname):
257252
get('r2-times.txt', '%s/%s-r2-times.txt' % (env.expname, env.host))
258253

259254
with lcd(env.expname):

Diff for: rsc.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def __init__(self, fname, keys):
7373
except:
7474
self.Tx = {}
7575

76+
self.saving_lock = False
77+
7678
def add(self, Tx):
7779
ptx = rscoin.Tx.parse(Tx)
7880
for i, (key_id, value) in enumerate(ptx.outTx):
@@ -82,8 +84,14 @@ def add(self, Tx):
8284
def remove(self, desc):
8385
del self.Tx[desc]
8486

85-
def save(self):
87+
def save(self, reactor):
88+
if not self.saving_lock:
89+
self.saving_lock = True
90+
reactor.callInThread(self._save)
91+
92+
def _save(self):
8693
dump(self.Tx, file(self.fname, "wb"))
94+
self.saving_lock = False
8795

8896
def balances(self):
8997
balances = defaultdict(int)
@@ -353,7 +361,7 @@ def play_another_song(var):
353361
for k in txs:
354362
active.remove(k)
355363

356-
active.save()
364+
active.save(reactor)
357365

358366
## Now run the on-line checking
359367
sechash, query_string, core = package_query(newtx, inTx_list, keys_list)
@@ -415,7 +423,7 @@ def r_process(results):
415423

416424
active = ActiveTx("activetx.log", keys)
417425
active.add(tx_ser)
418-
active.save()
426+
active.save(reactor)
419427

420428
print " ".join(core)
421429

0 commit comments

Comments
 (0)