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

How can I make a program to operate another program? [closed]
How to get the Skype username using skype calling feature
How to Resolve this issue “Could not find a stock quote for GOOGL or some other company names”
Open messenger chatbot webview extension in Chrome
How to pass control from one LUIS method to another?
How to transfer conversation from Bot to human agents?
How to speak skype user with the bot using skype calling feature?
Test connection to your bot getting failed : Bot Framework
How to find out programs communicate?
API.AI vs. WIT.AI from analytics and logging aspects
Call FormDialog from within a LUIS Dialog
How to access .wav file in bot simulator
How to call a LUIS Dialog outside of the MessagesController class
How to develop skype calling functionality using Azure Bot Service
Facebook Messenger List Template Display in Android
In LUIS, how to add list of synonym for each valid entry of entity? [closed]

Categories

HOME
php
xpath
mod-rewrite
mpdf
livecode
workflow
adobe
web2py
gentelella
elk-stack
angular-meteor
native-base
colors
orc
multi-step
max-msp-jitter
mahout-recommender
synthesis
office-ui-fabric
boomi
angular2-highcharts
azure-machine-learning
multi-upload
generator
python-appium
hevc
network-analysis
macromedia
spring-annotations
sales
ibm-connections
es6-modules
toad
snap-framework
john-the-ripper
microsoft-certifications
custom-keyboard
des
cloudera-quickstart-vm
hidden-markov-models
extbase
android-n
widestring
spooler
ssi
nothing
password-hash
redisson
dblink
apache-modules
mpmovieplayercontroller
bpms
pjax
metabase
okio
fuzzer
urbit
flush
flask-security
diawi
msgpack
variable-length-array
arbre
self
canopy
compositetype
ampersand
tree-structure
webproject
nhibernate-criteria
microsoft-expression-web
rubber
device-admin
webaii
pre
pbkdf2
rautomation
stty
statechart
reentrancy
ntlmv2
session-0-isolation
java.lang.class
will-paginate
android-2.1-eclair
chunking
ixmldomdocument
cleartype
gtktextview
database-cloning
rendering-engine

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App