dshmvqnl98119 2016-03-24 02:11
浏览 32

处理来自服务器端的快速顺序get请求?

I'm editing an open source web server to host data from the Android app Torque. Torque connects to an ODBII adapter in the car, logs data, then uploads it to the server in the form of a get request at a desired interval (in this case, 1 per second).

The codebase when I started stored everything in 1 mysql table, then used some mysql distinct statements to pull out "session" info (which was just repeated on every line of the logged data). My fork intends to create a second "sessions" table which stores distinct info, leaving only the momentary info in the large table.

Each get request from the app appears to wait for an "Ok!" returned from the html interface.

What I'm finding is, my logic and multiple queries take a bit longer to return, and the net result is that datapoints aren't getting logged. Yesterday (before my commit) my commute logged ~1900 datapoints; today (after my commit) it only logged 52. In my apache access logs, I see 52 access attempts. thousands of attempts.

I don't have the ability to edit/modify the app, so I'm stuck trying to re-mediate this from the server side. I'm only intermediate at coding in PHP. What techniques can I use to speed up the return code, or what can I do from the server side to produce the return code immediately allowing for another datapoint to be logged? Is it as simple as moving the echo statement up in the code? Is there a best practice I'm missing?

I'm going to try to move the response code up and possibly trigger an output buffer flush. Also, I'm gonna decrease the logging interval to 5 seconds. Hopefully those things will help.

Unfortunately, the entire code piece is suspect; I'll add the statement I added (thus believe is the trouble) but I don't think it's limited to this:

if ((sizeof($sesskeys) === sizeof($sessvalues)) && sizeof($sesskeys) > 0) {
  // See if there is already an entry in the sessions table for this session
  $sessionqry = mysql_query("SELECT session, sessionsize FROM $db_sessions_table WHERE session LIKE '$sessuploadid'", $con) or die(mysql_error());
  if (mysql_num_rows($sessionqry) > 0) {
    // If there's an entry in the session table for this session, update the session end time and the datapoint count
    while($row = mysql_fetch_assoc($sessionqry)) {
      $sesssizecount = $row["sessionsize"] + 1;
      $sessionqrystring = "UPDATE $db_sessions_table SET timeend='$sesstime', sessionsize='$sesssizecount' WHERE session LIKE '$sessuploadid'";
      mysql_query($sessionqrystring, $con) or die(mysql_error());
    }
  } else {
    // If this is a new session, insert an entry in the sessions table and then update the start time and datapoint count
    $sql = "INSERT INTO $db_sessions_table (".implode(",", $sesskeys).") VALUES (".implode(",", $sessvalues).")";
    mysql_query($sql, $con) or die(mysql_error());
    $sql = "UPDATE $db_sessions_table SET timestart='$sesstime', sessionsize='1' WHERE session LIKE '$sessuploadid'";
    mysql_query($sql, $con) or die(mysql_error());
  }
}

Before my commits: https://github.com/econpy/torque/blob/master/web/upload_data.php

After my commits: https://github.com/surfrock66/torque/blob/master/web/upload_data.php

Server: Ubuntu Server 15.10. Apache 2.4.12. Php 2.6.0 through mod php. MySQL 5.6.28.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度