bots


Bot becomes slow over time in loop


I have a case where my bot repeatedly asks quiz questions and the custom prompt ends only when the user fails to answer correctly or times out. If I clear all conversation data with the user, initially the interaction is very smooth but as I go over 50 questions or so, it becomes slower and slower till the point where the bot is unusable. There is a noticeable amount of lag between the time the person clicks the button and the button click is acknowledged. This would be the code for my custom prompt. Any ideas what is happening
See this VISUALLY HERE
'use strict';
const
builder = require('botbuilder'),
engine = require('./engine'),
emoji = require('node-emoji'),
strings = require('./madmathstrings')
const
MADMATH_ROUND_TIMEOUT = parseInt(process.env.MADMATH_ROUND_TIMEOUT) || 10,
MADMATH_ROUND_TIMEOUT_BUFFER = parseInt(process.env.MADMATH_ROUND_TIMEOUT_BUFFER) || 2,
DIALOG_NAME = 'madmath'
module.exports.beginDialog = function (session, options) {
session.beginDialog(DIALOG_NAME, options);
}
module.exports.create = function (bot) {
let prompt = new builder.IntentDialog()
.onBegin(onQuestion)
.onDefault(onAnswer);
bot.dialog(DIALOG_NAME, prompt);
}
function onQuestion(session, args) {
/**Record start time for logging purposes */
let start = new Date().getTime()
let buttons = []
let dialogData = session.dialogData
/**What is the difficulty level, 0 or 1 or 2 */
dialogData.difficulty = args ? args.difficulty : 0
/**The current index of the question */
dialogData.index = args ? args.index : 0
/**A maximum value used to generate random numbers below it */
dialogData.max = args ? args.max : 10
/**A minimum value used to generate random numbers above it */
dialogData.min = args ? args.min : 0
/**The total points scored by the user so far */
dialogData.score = args ? args.score : 0
/**Text indicating the level number */
let level
/**Check if it is the 5th question, 10th question, 15th ... */
if ((dialogData.index + 1) % 5 === 0) {
/**Increase the difficulty level by 1 so that it goes from 0 to 1 or 1 to 2 or 2 to 0 */
dialogData.difficulty = (dialogData.difficulty + 1) % 3
dialogData.min = dialogData.min + 1
dialogData.max = dialogData.max + 5
}
/**Displays Level 0 on top of the 1st question*/
if (dialogData.index === 0) {
level = `Level 1`
}
/**Displays level N at the top of every 5th question */
else if ((dialogData.index + 1) % 5 === 0) {
level = `Level ${((dialogData.index + 1) / 5) + 1}`
}
/**No levels are displayed for intermediate questions */
else {
level = ''
}
/**Get the minimum and maximum as negative or positive numbers in a random fashion */
let min, max
/**a positive min number and a positive maximum number */
if (Math.floor(Math.random() * 2) === 1) {
min = dialogData.min
max = dialogData.max
}
/**A negative minimum number and a negative maximum number */
else {
min = -dialogData.max
max = -dialogData.min
}
/**Generate a Math problem with 3 choices for an answer at the given difficulty level in the range supplied by minimum and maximum */
let question = engine.puzzleMath(3, dialogData.difficulty, min, max)
/**Convert the choices from Number to String to be used inside a button */
question.choices.map(
item => buttons.push(
new builder.CardAction.imBack(
session, item.toString(), ` ${item.toString()} `
)
)
)
/**Send the question with the level information if available, the index and the Math expression along with a countdown timer as GIF attachment */
session.send(new builder.Message(session)
.text(level ? level + ' \n' + strings.question : strings.question, dialogData.index + 1, question.expression)
.addAttachment(
new builder.AnimationCard(session)
.media([{
profile: "image/gif",
url: 'https://media.giphy.com/media/l3q2silev6exF53pu/200w.gif'
}])
.buttons(buttons)
))
/**Store the question to be referenced later while checking for an answer */
dialogData.question = question
/**Record the current time as the time when the question was presented to the user*/
dialogData.startTime = new Date().getTime()
/**Record the end time for running all the code inside this method for logging purposes */
let end = new Date().getTime()
console.log(`${(end - start) / 1000} seconds`)
}
function onAnswer(session) {
/**Record start time of this method for logging purposes */
let start = new Date().getTime()
let dialogData = session.dialogData, guess, isCorrect, isValid, onTime = false, speedMultiplier = 0
/**Get the time when the user sent the answer */
dialogData.endTime = new Date(session.message.timestamp).getTime()
/**Find the difference between the time the user saw the question and answered it */
let duration = Math.floor((dialogData.endTime - dialogData.startTime) / 1000)
//If the difference is less than 5 seconds, we give a 1000 points
if (duration <= MADMATH_ROUND_TIMEOUT_BUFFER) {
speedMultiplier = 10;
onTime = true;
}
//If the difference is between 5 - 15 seconds, we give them 100 points per second of speed
else if (duration < MADMATH_ROUND_TIMEOUT + MADMATH_ROUND_TIMEOUT_BUFFER) {
/**
* If the total timeout is 10 seconds and we have a buffer of 5 seconds,
* we calculate 10/10 * (10 + 5 - 7) = 8, 8 x 100 = 800 gives the number of points to be assigned to the user for this answer
*/
speedMultiplier = (10 / MADMATH_ROUND_TIMEOUT) * (MADMATH_ROUND_TIMEOUT + MADMATH_ROUND_TIMEOUT_BUFFER - duration)
/**The person has answered on time */
onTime = true;
}
//Assign the user 100 points at the 15th second
else if (duration === MADMATH_ROUND_TIMEOUT + MADMATH_ROUND_TIMEOUT_BUFFER) {
speedMultiplier = 1
onTime = true;
}
//The person did not answer on time
else {
speedMultiplier = 0
onTime = false
}
/**The value entered by the user */
guess = builder.EntityRecognizer.parseNumber(session.message.text)
/**Check if the user answered the question correctly */
isCorrect = dialogData.question.answer === guess
/**Check if the answer is a number */
isValid = !isNaN(guess)
/**If the person answered with the correct number on time */
if (isCorrect && isValid && onTime) {
/**Increase the index of the question */
dialogData.index++;
/**Increase the score of the user so far */
dialogData.score = dialogData.score + speedMultiplier * 100
/**Fire the next question */
session.replaceDialog(DIALOG_NAME, dialogData)
}
/**If the person did not answer on time */
else if (!onTime) {
/**How late is the person after 15 seconds */
let howLate = duration - (MADMATH_ROUND_TIMEOUT + MADMATH_ROUND_TIMEOUT_BUFFER)
/**Get the delay message to be shown to the user */
let text = strings.timeout(howLate)
/**Show a GIF image representing timeout */
let message = new builder.Message(session)
.attachments([
new builder.AnimationCard(session)
.title(text.title)
.subtitle(text.subtitle)
.media([{
profile: "image/gif",
url: 'http://media1.giphy.com/media/26uTt2zN11nFuyH1C/200w.gif'
}])
])
session.send(message)
/**End the round indicating the score and the longest streak */
session.endDialogWithResult({
score: dialogData.score,
streak: dialogData.index
})
}
/**If the person answered incorrectly or with an invalid response */
else {
/**End the round indicating the score and the longest streak */
session.endDialogWithResult({
score: dialogData.score,
streak: dialogData.index
})
}
/**Record end time of this method for logging purposes */
let end = new Date().getTime()
console.log(`${(end - start) / 1000} seconds`)
}
Am I leaking data anywhere. Any ideas how I can resolve this increasing amount of delay
UPDATE 1
I tried this after setting autoBatchDelay to 0 and the problem still remains

Related Links

Best way to find moving function for a bot
api.ai domain intent query response
How to define string as luis entity
Luis V2 Remove action parameter/prompt
Telegram Bot PHP keyboard doesn't works
How can I use PromptDialog.Choice while allowing the user to type the options without worrying about accented letters?
Messenger Bot Webview not closing on IOS
Slack bot cannot post message to private channel
Slack bot to pre-format channel responses
Is it possible to display a table in skype from bot framework?
Connecting api of android app to bot framework
IntentDialog matches only once at the start in bot framework
Multiple assistant.ask or assistant.tell statement without user input
Api.ai be public for all not only for tester, developer, admin
How do I count the number of users in my quiz bot?
scope of questions in api.ai

Categories

HOME
cocoapods
azure-functions
shinyapps
enums
key
loopbackjs
code-formatting
google-play-services
mosquitto
azure-mobile-services
clone
fedora
ag-grid
telegraf
responsive-design
tup
port
yahoo
colors
nsstring
fbloginview
outlook-restapi
trace32
android-5.1.1-lollipop
susy-sass
salt-cloud
libgit2
batch-rename
channel
dragula
sfml
sparkle
es6-modules
toad
winsock
location-services
actframework
android-canvas
polyml
forms-authentication
gitolite
linq.js
system-on-chip
access-denied
jqgrid-asp.net
return-type
redisson
simple-schema
instafeedjs
fitbit
cocoa-bindings
mifos
java-2d
jenkins-workflow
nsdata
openseadragon
perforce-integrate
timestamping
management-studio-express
android-expansion-files
ioctl
astropy
libz
nsmutabledata
dos2unix
dnsjava
ecos
aho-corasick
webautomation
rpg
mfmessagecomposeview
jini
redpitaya
miglayout
gpu-programming
mod-perl
illuminate-container
application-server
mousemotionlistener
rautomation
.net-remoting
jacob
acceptance-testing
dynamic-rdlc-generation
dibs
chefspec
proc-open
uitextfielddelegate
uipangesturerecognizer
net-use
representation
nsrangeexception
fork-join
upshot
django-pagination
eaccelerator
solandra
ixmldomdocument
raw-data
eventaggregator
firephp
database-cloning
autobench
objectinstantiation
account-management

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App