No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cbl.sh 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. #!/bin/bash
  2. #
  3. # CBL : Curl Benchmark on Lodel
  4. #
  5. # Usage : $0 [HOSTNAME] [INSTANCE_LIST_FILE]
  6. #
  7. # Instance_list_file is expected to be a file containing instances name (1 per
  8. # line). Uses by default /tmp/lodel2_instance_list.txt
  9. #
  10. # Instances base URL are generated given the current webui implementation :
  11. # http://HOST/INSTANCE_NAME/
  12. #
  13. #
  14. # Scenario description :
  15. #
  16. # mass_creation instance_name iteration_count :
  17. # Create iteration_count time a random leobject in given instance_name
  18. # note : do note create relation between objects, only populate content
  19. #
  20. # step 1 : fetch all non abstract class name
  21. # step 2 : loop on creation (using bash function curl_opt_create_CLSNAME)
  22. # that return the POST fields (populated with random values)
  23. #
  24. # mass_deletion instance_name iteration_count :
  25. # Foreach non asbtracty class delete iteration_count time an object of
  26. # current class in current instance
  27. #
  28. # step 1 : fetch all non abstract class name
  29. # step 2 : loop on non abstract class name
  30. # step 3 : loop iteration_count time on deletion
  31. #
  32. # mass_link_edit instance_name iteration_count :
  33. # Foreach non abstract class make iteration_count time edition of an
  34. # object in current class
  35. # note : only implemented for Person for the moment
  36. # note : can maybe ask for invalid modifications
  37. #
  38. # step 1 : fetch all non abstract class name
  39. # step 2 : loop on non abstract class name
  40. # step 3 : depends on curent class :
  41. # - fetch all existing id of current class
  42. # - fetch all existing id in class that can be linked with
  43. # current class
  44. # step 4 : loop iteration_count time :
  45. # - choose a random id in current class
  46. # - choose random ids from linkable classes
  47. # - trigger edition using curl (with datas from the same
  48. # bash function than creation : curl_opt_create_CLSNAME)
  49. #
  50. # Current way to run scenarios :
  51. #
  52. # using the function run_bg_with_param FUNCTION_NAME INSTANCE_LIST_FILE *ARGS
  53. #
  54. # The function name can be one of the scenario functions
  55. # INSTANCE_LIST_FILE is the file containing instances list
  56. # *ARGS are args given as it to FUNCTION_NAME after the instance_name argument
  57. #
  58. # function call : FUN_NAME INSTANCE_NAME *ARGS
  59. #
  60. # The run_bg_with_param run a scenario in background for each instance allowing
  61. # to send a lot of request at the same time
  62. #
  63. #
  64. usage() {
  65. echo "Usage : $0 [HOSTNAME] [INSTANCE_LIST_FILE]"
  66. exit
  67. }
  68. host=$1
  69. host=${host:=localhost}
  70. instance_list=$2
  71. instance_list=${instance_list:=/tmp/lodel2_instance_list.txt}
  72. logdir="/tmp/lodel2_cbl_logs"
  73. if [ -d "$logdir" ]
  74. then
  75. echo "WARNING : $logdir allready exists. It's a better idea to delete it before running this script again"
  76. echo "waiting 3s"
  77. sleep 3
  78. fi
  79. mkdir -p $logdir
  80. #curl_options='--silent -o /dev/null -s -w %{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total}\n'
  81. curl_options='--silent -o /dev/null -s -w %{url_effective};%{http_code};%{time_connect};%{time_starttransfer};%{time_total}\n'
  82. curl_debug_opt='-v -w %{url_effective};%{http_code};%{time_connect};%{time_starttransfer};%{time_total}\n'
  83. curl_cmd="curl $curl_options"
  84. curl_raw="curl --silent"
  85. curl_debug="curl $curl_debug_opt"
  86. curcurl="$curl_cmd"
  87. cmktemp="mktemp -t lodel2_cbl_XXXXXXXX"
  88. _base_uri() {
  89. echo -n "http://$host/$1"
  90. }
  91. rnd_str() {
  92. len=$1
  93. cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $len | head -n 1
  94. }
  95. rnd_str_len() {
  96. minlen=$1
  97. maxlen=$2
  98. cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $(shuf -i${minlen}-${maxlen} -n1) | head -n 1
  99. }
  100. mass_creation() {
  101. #mass creation scenario
  102. #$1 is instance name
  103. #$2 is iteration count (1 iteration is 1 creation of a random class)
  104. instance_name=$1
  105. iteration_count=$2
  106. base_uri=$(_base_uri $1)
  107. logfile="$logdir/mass_creation_${instance_name}.log"
  108. cls_list_file=$(fetch_all_classes $1)
  109. for i in $(seq $iteration_count)
  110. do
  111. cls=$(shuf -n1 $cls_list_file)
  112. $curcurl -d "$(curl_opt_create_$cls)" "${base_uri}$(uri_create $cls)" | tee -a $logfile
  113. done
  114. rm -v $cls_list_file
  115. }
  116. mass_link_edit() {
  117. #mass linking & edition scenarion
  118. #$1 is instance name
  119. #$2 is iteration count
  120. instance_name=$1
  121. iteration_count=$2
  122. base_uri=$(_base_uri $1)
  123. logfile="$logdir/mass_link_edit_${instance_name}.log"
  124. cls_list_file=$(fetch_all_classes $1)
  125. for cls in $(cat $cls_list_file)
  126. do
  127. case $cls in
  128. Person)
  129. person_ids=$(fetch_all_ids $1 Person)
  130. section_ids=$(fetch_all_ids $1 Section)
  131. subsection_ids=$(fetch_all_ids $1 Section)
  132. text_ids=$($cmktemp)
  133. cat $section_ids $subsection_ids | shuf > $text_ids
  134. for i in $(seq $iteration_count)
  135. do
  136. cur_id=$(shuf -n1 $person_ids)
  137. alias_count=$(shuf -i1-5 -n1)
  138. ltext_count=$(shuf -i1-5 -n1)
  139. alias_param=$(head -n $(expr $alias_count \* $i) $person_ids| tail -n$alias_count|tr -s "\n" ",")
  140. txt_param=$(head -n $(expr $ltext_count \* $i) $text_ids | tail -n$ltext_count|tr -s "\n" ",")
  141. $curcurl -d "$(curl_opt_create_$cls $alias_param $txt_param)&uid=$cur_id" "$base_uri/admin/update?classname=$cls&lodel_id=$cur_id" | tee -a $logfile
  142. done
  143. rm -v $text_ids $person_ids $section_ids $subsection_ids
  144. ;;
  145. *)
  146. ;;
  147. esac
  148. done
  149. rm -v $cls_list_file
  150. }
  151. mass_deletion() {
  152. #mass deletion scenario
  153. #$1 is instance name
  154. #$2 number of deletion per classes !
  155. instance_name=$1
  156. iteration_count=$2
  157. base_uri=$(_base_uri $1)
  158. logfile="$logdir/mass_deletion_${instance_name}.log"
  159. cls_list_file=$(fetch_all_classes $1)
  160. for cls in $(cat $cls_list_file)
  161. do
  162. id_list_file=$(fetch_all_ids $1 $cls)
  163. if [ "$iteration_count" -gt "$(wc -l $id_list_file | cut -d " " -f1)" ]
  164. then
  165. max_iter=$(wc -l $id_list_file | cut -d " " -f1)
  166. else
  167. max_iter="$iteration_count"
  168. fi
  169. for i in $(seq $max_iter)
  170. do
  171. id=$(tail -n $i $id_list_file | head -n1)
  172. $curcurl "${base_uri}/admin/delete?classname=$cls&lodel_id=$id" | tee -a $logfile
  173. done
  174. rm -v $id_list_file
  175. done
  176. rm -v $cls_list_file
  177. }
  178. fetch_all_classes() {
  179. #$1 is intance name
  180. cls_list_file=$($cmktemp)
  181. $curl_raw "$(_base_uri $1)/list_classes" | grep -v Abstract |sed -nE 's/^ *<li> +<a href="([^"]+)" target="_blank".*$/\1/p'|cut -d"=" -f2 > $cls_list_file
  182. echo $cls_list_file
  183. }
  184. fetch_all_ids() {
  185. # Fetch all ids of a class in an instance and shuffle them
  186. instance_name=$1
  187. classname=$2
  188. idfile=$($cmktemp)
  189. $curl_raw "$(_base_uri $1)/show_class?classname=$2" | sed -nE 's/^.*<li><a href="[^=]+=[^=]+=([0-9]+)".*$/\1/p' |shuf > $idfile
  190. echo $idfile
  191. }
  192. uri_create() {
  193. clsname=$1
  194. echo -n "/admin/create?classname=$1"
  195. }
  196. curl_opt_create_Person() {
  197. #$1 is alias id
  198. #$2 is linked_texts id (comma separated)
  199. echo "field_input_lastname=$(rnd_str_len 10 20)&field_input_firstname=$(rnd_str_len 10 20)&field_input_alias=$1&field_input_linked_texts=$2&classname=Person"
  200. }
  201. curl_opt_create_User() {
  202. echo "field_input_lastname=$(rnd_str_len 10 20)&field_input_firstname=$(rnd_str_len 10 20)&field_input_password=$(rnd_str 50)&field_input_login=$(rnd_str_len 5 20)&classname=User"
  203. }
  204. curl_opt_create_Collection() {
  205. #$1 is publications id (comma separated)
  206. echo "field_input_title=$(rnd_str_len 20 50)&field_input_publications=$1&classname=Collection"
  207. }
  208. curl_opt_create_Publication() {
  209. #$1 collections id comma separated
  210. echo "field_input_collection=$1&classname=Publication"
  211. }
  212. curl_opt_create_Section() {
  213. #$1 childs id (comma separated)
  214. #$2 linked_persons id (comma separated)
  215. echo "field_input_title=$(rnd_str_len 20 50)&field_input_subtitle=$(rnd_str_len 20 50)&field_input_childs=$1&field_input_linked_persons=$2&classname=Section"
  216. }
  217. curl_opt_create_Subsection() {
  218. #$1 childs id (comma separated)
  219. #$2 linked_persons id (comma separated)
  220. #$3 parants id (comma separated)
  221. echo "field_input_title=$(rnd_str_len 20 50)&field_input_subtitle=$(rnd_str_len 20 50)&field_input_childs=$1&field_input_linked_persons=$2&field_input_parent=$3&classname=Subsection"
  222. }
  223. run_bg_with_param() {
  224. #$1 is the function name to run
  225. #$2 is the instance_list filename
  226. #other parameters are given to the function
  227. fun=$1
  228. instance_list=$2
  229. shift;shift
  230. pidlist=$($cmktemp)
  231. for iname in $(cat $instance_list)
  232. do
  233. $fun $iname $@ &
  234. echo $! >> $pidlist
  235. done
  236. for pid in $(cat $pidlist)
  237. do
  238. wait $pid
  239. done
  240. rm -v $pidlist
  241. }
  242. run_bg_with_param "mass_creation" $instance_list 50
  243. run_bg_with_param "mass_link_edit" $instance_list 10
  244. run_bg_with_param "mass_deletion" $instance_list 10
  245. echo ""
  246. echo "Logs can be found in $logdir"