1#!/usr/bin/env tclsh
2package require XOTcl; namespace import -force xotcl::*
3
4#  ./get-regression-nb.xotcl -host swt -parallel 0
5#  ./get-regression-nb.xotcl -host swt -sequential 0
6#
7# mit ~/wafe/src/cineast/webserver.xotcl (benotigt ~/wafe/test/*)
8#  ./get-regression-nb.xotcl  -port 8086
9#
10# Vergleich webserver.xotcl mit Apache:
11# 1) installation von Apache auf port 80
12#
13# 2) installation vom webserver.xotcl auf port 8086
14#
15# 3) von beiden server sollend die files in wafe/test/* unter
16#    http://SERVER+PORT/test/*
17#    erreichbar sein.
18#
19# 4) test der installation
20#    apache:
21#         cd wafe/src/cineast
22#         get-regression-nb.xotcl -sequential 0 
23#      die ausgabe sollte mit totalbytes=6536120
24#      abgeschlossen werden
25#
26#    webserver.xotcl:
27#         cd wafe/src/cineast
28#         get-regression-nb.xotcl -port 8086 -sequential 0 
29#      die ausgabe sollte mit totalbytes=6536120
30#      abgeschlossen werden
31#
32# 5) grosser testlauf:
33#    rsh muss funktionieren: z.B.:   rsh localhost date
34#    
35#    apache:
36#         cd wafe/src/cineast
37#         time get-regression-nb.xotcl -sequential 0 -clients 1
38#
39#    webserver.xotcl:
40#         cd wafe/src/cineast
41#         time get-regression-nb.xotcl -port 8086 -sequential 0 -clients 1
42#
43# Ergebnisse auf meinem Rechner:
44#
45# der xotcl-webserver ist etwa 20% langsamer als apache.
46# das logging (instproc log) aktivieren kostet ein paar weitere prozent....
47# -gn
48#
49# mohegan:~/wafe/src/cineast> time ./get-regression-nb.xotcl -port 8086 -sequential 0 -clients 1
50# Loading source file ~/wafe/src/cineast/Access.xotcl
51# Loading source file ~/wafe/src/cineast/PCache.xotcl
52# Loading source file ~/wafe/src/cineast/Connection.xotcl
53# Loading source file ~/wafe/src/cineast/trace.xotcl
54#  1 clients:   3.07 seconds  (per client   3.07 seconds, 2127.31 KB/sec) server: 2127.31 KB/sec
55#  2 clients:   6.36 seconds  (per client   3.18 seconds, 1028.10 KB/sec) server: 2056.20 KB/sec
56#  3 clients:   7.71 seconds  (per client   2.57 seconds,  847.74 KB/sec) server: 2543.22 KB/sec
57#  4 clients:  11.21 seconds  (per client   2.80 seconds,  582.92 KB/sec) server: 2331.66 KB/sec
58#  5 clients:  10.57 seconds  (per client   2.11 seconds,  618.49 KB/sec) server: 3092.45 KB/sec
59# 10 clients:  25.07 seconds  (per client   2.51 seconds,  260.68 KB/sec) server: 2606.79 KB/sec
60# 20 clients:  45.48 seconds  (per client   2.27 seconds,  143.73 KB/sec) server: 2874.58 KB/sec
61#0.420u 0.450s 1:49.65 0.7%      0+0k 0+0io 113263310pf+0w
62#
63#
64#
65# mohegan:~/wafe/src/cineast> time ./get-regression-nb.xotcl -port 80 -sequential 0 -clients 1
66# Loading source file ~/wafe/src/cineast/Access.xotcl
67# Loading source file ~/wafe/src/cineast/PCache.xotcl
68# Loading source file ~/wafe/src/cineast/Connection.xotcl
69# Loading source file ~/wafe/src/cineast/trace.xotcl
70#  1 clients:   1.85 seconds  (per client   1.85 seconds, 3542.58 KB/sec) server: 3542.58 KB/sec
71#  2 clients:   4.71 seconds  (per client   2.36 seconds, 1387.02 KB/sec) server: 2774.03 KB/sec
72#  3 clients:   4.09 seconds  (per client   1.36 seconds, 1596.58 KB/sec) server: 4789.74 KB/sec
73#  4 clients:   7.74 seconds  (per client   1.94 seconds,  844.43 KB/sec) server: 3377.71 KB/sec
74#  5 clients:   9.46 seconds  (per client   1.89 seconds,  690.67 KB/sec) server: 3453.33 KB/sec
75# 10 clients:  20.91 seconds  (per client   2.09 seconds,  312.52 KB/sec) server: 3125.24 KB/sec
76# 20 clients:  39.01 seconds  (per client   1.95 seconds,  167.55 KB/sec) server: 3351.08 KB/sec
77#0.410u 0.360s 1:27.95 0.8%      0+0k 0+0io 112251994pf+0w
78#
79#
80
81set CACHE_DIR [::xotcl::tmpdir]
82
83package require xotcl::comm::httpAccess
84package require xotcl::trace
85
86set port ""
87set host localhost
88set cachingopts {0 1 2 2}
89set parallel 1
90set sequential 0
91set clients 0
92set local 1
93
94foreach {att val} $argv {
95  switch -exact -- $att {
96    -port {set port $val}
97    -host {set host $val}
98    -memory {set cachingopts 0}
99    -parallel {set parallel $val}
100    -sequential {set sequential $val}
101    -clients {set clients $val}
102    -local {set local $val}
103  }
104}
105
106set hosts {
107  R2H2-11   R2H2-12   R2H2-13   R2H2-21   R2H2-22   R2H2-23   R2H2-31 R2H2-32 
108  R2H2-33   R2H2-41   R2H2-42   R2H2-43   R2H2-51   R2H2-52   R2H2-53 R2H2-61 
109  R2H2-62   R2H2-63   R2H2-73   
110  matush  nashawag  sagumumpsketuck  wawog  willimantic  wonkituck  mashipaug
111  watuppa
112}
113#set hosts {
114#  matush  nashawag  sagumumpsketuck  wawog  willimantic  wonkituck  mashipaug
115#  R2H2-11   R2H2-12   R2H2-13   R2H2-21   R2H2-22   R2H2-23   R2H2-31 R2H2-32 
116#  R2H2-33   R2H2-41   R2H2-42   R2H2-43   R2H2-51   R2H2-52   R2H2-53 R2H2-61 
117#  R2H2-62   R2H2-63   R2H2-73   
118#  watuppa
119#}
120set totalbytes 6536120
121set totalbytes 1293240;# ohne 5m request
122
123
124if {$clients} {
125  proc readable {handle rhost} {
126    if {[eof $handle]} {
127      incr ::running -1
128      if {[catch {close $handle} output]} {
129	if {![string match *$::totalbytes $output]} {
130	  puts stderr "invalid output on client on host $rhost"
131	  puts stderr "***********************************"
132	  puts stderr $output
133	  puts stderr "***********************************"
134	}
135      }
136      #puts stderr clients=$::running
137      if {$::running == 0} {
138	set ::xxx 1
139      }
140    } else {
141      gets $handle
142    }
143  }
144  proc clients {clients} {
145    append cmd "[pwd]/$::argv0 -host $::host " \
146	"-parallel $::parallel -sequential $::sequential"
147    if {$::port ne ""} {append cmd " -port $::port"}
148    set starttime [clock clicks]
149    set ::running $clients
150    for {set s 0} {$s < $clients} {incr s} { 
151      if {$::local} {
152	set rhost localhost
153      } else {
154	set rhost [lindex $::hosts $s]
155      }
156      #puts stderr "rsh $rhost $cmd"
157      puts -nonewline stderr "$rhost "
158      set f($s) [open "| rsh $rhost $cmd"]
159      fconfigure $f($s) -blocking 0
160      fileevent $f($s) readable "readable $f($s) $rhost"
161    }
162    puts stderr ""
163    vwait ::xxx
164    set secs [expr {([clock clicks] -$starttime)/1000000.0}]
165    puts stderr "[format %3d $clients] clients: [format %6.2f $secs] seconds \
166	(per client [format %6.2f [expr {$secs/$clients}]] seconds,\
167	[format %7.2f [expr {$::totalbytes/($secs*1000.0)}]] KB/sec)\
168	server: [format %7.2f [expr {$::totalbytes*$clients/($secs*1000.0)}]] KB/sec"
169  }
170  clients 1
171  clients 2
172  clients 3
173  clients 4
174  clients 5
175  clients 10
176  clients 20
177  exit
178}
179
180persistentCache clear
181
182proc assert {f r} {
183  set got [eval $f]
184  if {$got ne $r } {
185    puts stderr "assertion failed: \[$f\] == $r (got $got)" 
186    quit
187  } else {
188    puts stderr "OK $r = $f"
189  }
190}
191proc head msg {
192  puts stderr ""
193  puts stderr "---------------------------- $msg"
194}
195
196proc test {msg cmd} {
197  set r [Object autoname r]
198  head $msg
199  if {[catch {eval $cmd} msg]} {
200    puts stderr "ERROR: $::errorInfo"
201    quit
202  }
203  $r destroy
204}
205
206Object userPwd 
207userPwd proc user {u} { 
208  my set user $u
209}
210userPwd proc show {realm userVar pwVar} {
211  upvar $userVar u $pwVar pw
212  set u [my set user]
213  set pw jogl
214  return 1
215}
216
217
218
219
220# test "simple request" {
221#   SimpleRequest $r -caching 0 \
222#       -url http://localhost/index.html
223#   assert "$r getContentLength" 81
224# }
225# test "simple request" {
226#   SimpleRequest $r -caching 1 \
227#       -url http://localhost/index.html
228#   assert "$r getContentLength" 81
229# }
230# test "simple request" {
231#   SimpleRequest $r -caching 1 \
232#       -url http://localhost/index.html
233#   assert "$r getContentLength" 81
234# }
235# test "simple request" {
236#   persistentCache invalidate \
237#       http://localhost/index.html
238#   SimpleRequest $r -caching 1 \
239#       -url http://localhost/index.html
240#   assert "$r getContentLength" 81
241# }
242
243# test "simple request" {
244#   SimpleRequest $r -caching 0 \
245#        -url http://localhost/muster-d1klausur.ps
246#   assert "$r getContentLength" 163840
247# }
248set total 0
249proc parallelRequests-1.0 {urls} {
250  ParallelSink psink -httpVersion 1.0 -init -requests $urls
251  incr ::total [psink set totalbytes]
252  psink destroy
253}
254proc parallelRequests-1.1 {urls} {
255  ParallelSink psink -init -requests $urls
256  incr ::total [psink set totalbytes]
257  psink destroy
258}
259if {$port ne ""} {set port :$port}
260
261
262if {$parallel} {
263  parallelRequests-1.0 [list \
264			http://$host$port/test/file500.html \
265			http://$host$port/test/file5k.html \
266			http://$host$port/test/file50k.html \
267			http://$host$port/test/file500k.html \
268			http://$host$port/test/file5m.html \
269			http://$host$port/test/file500.html \
270			http://$host$port/test/file5k.html \
271			http://$host$port/test/file5k.html \
272			http://$host$port/test/file500.html \
273			http://$host$port/test/file500.html \
274			http://$host$port/test/file5k.html \
275			http://$host$port/test/file5k.html \
276			http://$host$port/test/file500.html \
277			http://$host$port/test/file5k.html \
278			http://$host$port/test/file5k.html \
279			http://$host$port/test/file500.html \
280		       ]
281  for {set i 1} {$i<10} {incr i} {
282    parallelRequests-1.1 [list \
283			      http://$host$port/test/file50k.html \
284			      http://$host$port/test/file5k1.html \
285			      http://$host$port/test/file5k2.html \
286			      http://$host$port/test/file5k3.html \
287			      http://$host$port/test/file5k4.html \
288			      http://$host$port/test/file5k5.html 
289			 ]
290  }
291  puts stderr totalbytes=$::total
292}
293
294if {$sequential} {
295  set doc http://$host$port/test/suexec.html
296  set size 20680
297  foreach c $cachingopts {
298    test "caching $c $doc" {
299      SimpleRequest $r -caching $::c -url $::doc
300      assert "$r getContentLength" $::size
301      #puts stderr c=<[$r getContent]>
302    }
303  }
304  
305  set doc http://$host$port/test/xvdocs.ps
306  set size 3678303
307  foreach c $cachingopts {
308    test "caching $c" {
309      SimpleRequest $r -caching $::c -url $::doc
310      assert "$r getContentLength" $::size
311    }
312  }
313  
314}
315exit
316
317test "simple request" {
318  SimpleRequest $r -caching 0 \
319      -url http://nestroy.wi-inf.uni-essen.de/Raumplan.html
320  assert "$r getContentLength" 662
321}
322
323
324test "simple request, larger file" {
325  SimpleRequest $r -caching 0 \
326      -url http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
327  assert "$r getContentLength" 349970
328}
329
330
331test "use cache" {
332  SimpleRequest $r -caching 1 \
333      -url http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
334  assert "$r getContentLength" 349970
335}
336
337
338test "specify filename, use cache and validate request" {
339  persistentCache invalidate \
340      http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
341  exec rm -f test.ps
342  SimpleRequest $r -caching 1 -fileName test.ps \
343      -url http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
344  assert "$r getContentLength" 349970
345  assert "file size test.ps" 349970
346  assert {lindex [exec md5sum  test.ps] 0} c6029c987e841430f3ca9bab157da12f
347}
348
349
350test  "specify filename, and use cache and a validated file" {
351  exec rm -f test.ps
352  SimpleRequest $r -caching 1 -fileName test.ps \
353      -url http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
354  assert "$r getContentLength" 349970
355  assert "file size test.ps" 349970
356  assert {lindex [exec md5sum  test.ps] 0} c6029c987e841430f3ca9bab157da12f
357}
358
359test "specify filename, and do not use cache" {
360  exec rm -f test.ps
361  SimpleRequest $r -fileName test.ps -caching 0 \
362      -url http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
363  assert "$r getContentLength" 349970
364  assert "file size test.ps" 349970
365  assert {lindex [exec md5sum  test.ps] 0} c6029c987e841430f3ca9bab157da12f
366}
367
368test "specify filesink and use cache; no copying neccesary" {
369  persistentCache invalidate \
370      http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
371  SimpleRequest $r -useFileSink 1 -caching 1 \
372      -url http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
373  assert "$r getContentLength" 349970
374  assert "file size test.ps" 349970
375}
376
377
378
379test "load a large file to the cache" {
380  persistentCache clearEntry http://swt.wi-inf.uni-essen.de/lx2.1.55
381  SimpleRequest $r -caching 1 \
382      -url http://swt.wi-inf.uni-essen.de/lx2.1.55
383  assert "$r getContentLength" 522411
384}
385
386
387
388test  "load a validated large file" {
389  SimpleRequest $r -caching 1 \
390      -url http://swt.wi-inf.uni-essen.de/lx2.1.55
391  assert "$r getContentLength" 522411
392}
393
394test "pure loading test without cache" {
395  SimpleRequest $r -caching 0 \
396      -url http://swt.wi-inf.uni-essen.de/lx2.1.55
397  assert "$r getContentLength" 522411
398}
399
400
401test  "redirect" {
402  SimpleRequest $r -caching 1 \
403      -url http://mohegan.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
404  assert "$r getContentLength" 349970
405}
406
407
408test  "authentication" {
409  SimpleRequest $r -caching 1 \
410      -url http://nestroy.wi-inf.uni-essen.de/cgi-bin/w3-msql/Forschung/Publikationen/protected/index.html
411  assert "$r getContentLength" 1164
412}
413
414puts stderr after
415quit
416
417
418### request joining
419### load to file depending on content type
420