Backendless Support
 
Waiting for user's response

Simple business code timeout

Hi,

I have very simple business logic that

  1. looks up an entry in a table with little over 100 objects
  2. updates the entry if it exists or creates an object otherwhise

The code is run after login (actually after adding or updating an entry to a login sessions table which is done after login).

I got a couple of emails before that the business code was interrupted because it took longer than 5 seconds. I find it very strange that this code (which I will add below) would take more than 5 seconds to run but thought there just was a hickup.

Today however, our clients are not able to log in. I immediately suspected the business code so I disabled the events and logins started working again.

How could the code below cause these issues?

  1. System.out.println("Adding logon counter for " + session.getUser().getProperty("username") + " - " + session.getAppName() + " - " + session.getSource());
  2. // Current date
  3. Date date = new Date();
  4. DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  5. String dateStr = dateFormat.format(date);
  6. // Find logon counter for this user, application, source and date
  7. String where = "user.objectId = '" + session.getUser().getObjectId() + "'"
  8. + " AND appName = '" + session.getAppName() + "'"
  9. + " AND source = '" + session.getSource() + "'"
  10. + " AND loginDate = '" + dateStr + "'";
  11. BackendlessDataQuery query = new BackendlessDataQuery();
  12. query.setWhereClause(where);
  13. BackendlessCollection<LogonCounter> queryResult = Backendless.Persistence.of(LogonCounter.class).find(query);
  14. LogonCounter counter;
  15. // Update or create
  16. if(queryResult.getTotalObjects() > 0) {
  17. counter = queryResult.getData().get(0);
  18. counter.setCount(counter.getCount() + 1);
  19. } else {
  20. counter = new LogonCounter();
  21. counter.setUser(session.getUser());
  22. counter.setAppName(session.getAppName());
  23. counter.setSource(session.getSource());
  24. counter.setLoginDate(dateStr);
  25. counter.setCount(1);
  26. }
  27. LogonCounter savedCounter = Backendless.Persistence.save(counter);

Our application ID is C6730F91-F429-E4C9-FF61-ED62B2B2E100 and still runs in version 3 of the backend.

Kind regards,

Jeroen Dierckx

Leave a Comment

Comments (3)

photo
1

Hi Jeroen,

You could try to add logging statements to your code to see the exact point where the code hangs. In Backendless Online, there is a small possibility that sometimes business logic is being executed longer than expected (during peak times or server updates etc.), though it shouldn't happen really often.

Have you tried running the same code in debug mode today? Does it execute longer than expected, too?

photo
1

I will be able to try that later today - we have couple of deliverables that need to be finished first.

The code is not crucial: it is used for login statistics only.

photo
1

I think you might also make this handler async, so that it won't affect the request in case of failure.

photo