blog_mini bug修复记录1

blog_mini bug修复记录1

发现有篇文章只显示了一半。编辑之后再发布,还是只有一半。另外发布的时候感觉比较慢。

ab测试结果

ab -n 100 -c 10 http://blog.go2live.cn/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking blog.go2live.cn (be patient).....done


Server Software:        nginx/1.10.2
Server Hostname:        blog.go2live.cn
Server Port:            80

Document Path:          /
Document Length:        24039 bytes

Concurrency Level:      10
Time taken for tests:   14.268 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      2435000 bytes
HTML transferred:       2403900 bytes
Requests per second:    7.01 [#/sec] (mean)
Time per request:       1426.779 [ms] (mean)
Time per request:       142.678 [ms] (mean, across all concurrent requests)
Transfer rate:          166.66 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:   141 1350 261.7   1420    1497
Waiting:      140 1350 261.7   1420    1497
Total:        141 1350 261.6   1420    1497

Percentage of the requests served within a certain time (ms)
  50%   1420
  66%   1436
  75%   1455
  80%   1460
  90%   1473
  95%   1489
  98%   1492
  99%   1497
 100%   1497 (longest request)

应该说效率比较低。代码还要走读一直,看是直接增加memcache还是可以用插件的形式。

先修复内容只有一半的问题。
1.从相关的models,forms,views都没有看出问题。
2.通过抓包发现提交上去的内容并没有变少。
3.从数据库内容看,确实内容被截断了。

光看代码没有看出来。只有debug跟踪一下了。在python中debug可以用logging模块。

编辑config.py增加文件日志

  Rthandler = RotatingFileHandler(os.path.join(basedir,'../log/myapp.log'), maxBytes=100*1024*1024,backupCount=5)
  Rthandler.setLevel(logging.INFO)
  formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
  Rthandler.setFormatter(formatter)
  app.logger.addHandler(Rthandler)

最后发现居然是数据库的 Text字段不够长。。手动把结构改成了LongText。
找不半天没有发现flask-sqlalchemy的字段里支持LongText。

Tags: