Skip to content

Commit

Permalink
Merge pull request #3165 from jamalex/loadtesting_fix
Browse files Browse the repository at this point in the history
Loadtesting fix for Nalanda
  • Loading branch information
jamalex committed Mar 1, 2015
2 parents b289d0f + 0597547 commit a6d62e5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ writeup/
/content/*.mp4
/content/*.mp4.part
/content/*.srt
/content/khan
/data/logs
/data/i18n
/data/subtitles
Expand Down
40 changes: 21 additions & 19 deletions kalite/distributed/templates/distributed/loadtesting/load_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@

<script>

var fastInterval = 1000;
var slowInterval = 10000;
var fastInterval = 5000;
var slowInterval = 20000;

var PuppetModel = Backbone.Model.extend({

Expand Down Expand Up @@ -205,7 +205,7 @@
var task = tasks[index];
index++;
setTimeout(function() {
task.call(self, result, runNext);
task.call(self, result, _.once(runNext));
}, this.model.get("clickDelay"));
}
runNext(null, input);
Expand Down Expand Up @@ -268,15 +268,18 @@
},
function(input, callback) {
var numbers = this.$("span.mn")
var answer = 0
if (numbers.length == 0 || isNaN(Number(numbers[0].textContent))) {
callback("Question had not finished loading!")
}
var answer = 0;
if (Math.random() > 0.5) {
for (var i=0; i < numbers.length; i++){
for (var i = 0; i < numbers.length; i++) {
if (!isNaN(Number(numbers[i].textContent))) {
answer += Number(numbers[i].textContent)
answer += Number(numbers[i].textContent);
}
}
}
this.$("#solutionarea input").val(answer).keypress()
this.$("#solutionarea input").val(answer).keypress();
this.click("#check-answer-button");
callback()
}
Expand All @@ -287,12 +290,14 @@
this.goto("/securesync/login/", callback);
},
function(input, callback) {
var sidx = Math.ceil(Math.random() * {{ nusers }});
var username = "{{ username }}";

this.$("#id_facility option")[1].selected = true;
if (this.$("#id_facility option")[1]) {
this.$("#id_facility option")[1].selected = true;
}
this.fillForm({
username: "sssss" + sidx,
password: "sssss" + sidx,
username: username,
password: username,
});
this.submitForm(callback);
}
Expand All @@ -312,18 +317,15 @@
window.infobar = new InfoBarView({model: model, el: $("#infobar")});
puppet.goto(window.location.hash.slice(1) || "/");

function watchVideos() {
if(Math.random() < {{ pct_videos }}){
puppet.watchVideo(watchVideos);
function viewContent() {
if (Math.random() < {{ pct_videos }}) {
puppet.watchVideo(viewContent);
} else {
puppet.watchExercise(watchVideos);
}
if (Math.random() < {{ pct_logout }}) {
puppet.logout(function() { puppet.login(watchVideos); });
puppet.watchExercise(viewContent);
}
}

puppet.login(watchVideos);
puppet.login(viewContent);

});

Expand Down
1 change: 0 additions & 1 deletion kalite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def package_selected(package_name):

if package_selected("Nalanda"):
LOG.info("Nalanda package selected")
TURN_OFF_MOTIVATIONAL_FEATURES = True
RESTRICTED_TEACHER_PERMISSIONS = True
FIXED_BLOCK_EXERCISES = 5
QUIZ_REPEATS = 3
Expand Down
33 changes: 13 additions & 20 deletions kalite/testing/loadtesting/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import uuid

from annoying.decorators import render_to

from kalite.facility.models import Facility, FacilityUser


n_users_created = 0 # keep a global, to let us know if we've initialized, or need to re-initialize.

@render_to("distributed/loadtesting/load_test.html")
def load_test(request, nusers=None):
"""
Expand All @@ -20,26 +19,20 @@ def load_test(request, nusers=None):
So far the principal use for this has been testing with 30+ tablets connected over WiFi to a
server and seeing if the server and wireless connection can handle the strain.
"""
global n_users_created

if not n_users_created or n_users_created < int(request.GET.get("nusers", 1)): # default 1, as before
# It's either the first time, or time to add more
username = uuid.uuid4().hex[:12]

# Make sure there's a facility
if not Facility.objects.count():
fac = Facility.objects.create(name="fac")
fac = Facility.objects.all()[0]
# Make sure there's a facility
if not Facility.objects.count():
fac = Facility.objects.create(name="fac")
fac = Facility.objects.all()[0]

# Loop over all needed students
while n_users_created < int(request.GET.get("nusers", 1)):
n_users_created += 1
unpw = "sssss%d" % n_users_created
(user, _) = FacilityUser.get_or_initialize(username=unpw, facility=fac)
user.set_password(unpw)
user.save()
# Create the user
(user, _) = FacilityUser.get_or_initialize(username=username, facility=fac)
user.set_password(username)
user.save()

return {
"pct_videos": request.GET.get("pct_videos", 0.5),
"pct_logout": request.GET.get("pct_logout", 0.0),
"nusers": n_users_created,
"pct_videos": request.GET.get("pct_videos", 0.3),
"username": username,
}

0 comments on commit a6d62e5

Please sign in to comment.