V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
aeshfawre
V2EX  ›  Go 编程语言

有人用过 go 的 martini 框架么?

  •  
  •   aeshfawre · 2014-12-25 02:14:29 +08:00 · 1375 次点击
    这是一个创建于 3419 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用的是框架的demo,增加了一个get和post的处理

    m:=martini.Classic()
    m.Get("/add",AddTask)
    m.Post("/add",AddTask)
    
    func AddTask(res http.ResponseWriter,req *http.Request)string{
    //  req.ParseForm()
        u:=req.FormValue("u")
        p:=req.FormValue("p")
        return u+" "+p
    }
    

    这里是同样一个函数,为什么get方法和post方法的处理时间相差了100倍呢,我哪里用错了么,求教育

    [martini] Started POST /add for 192.168.1.103:4920
    [martini] Completed 200 OK in 225.794884ms
    [martini] Started POST /add for 192.168.1.103:4920
    [martini] Completed 200 OK in 226.507443ms
    [martini] Started GET /add for 192.168.1.103:4920
    [martini] Completed 200 OK in 1.674314ms
    [martini] Started GET /add for 192.168.1.103:4920
    [martini] Completed 200 OK in 1.099566ms

    10 条回复    2015-01-23 10:17:34 +08:00
    aeshfawre
        1
    aeshfawre  
    OP
       2014-12-25 10:45:07 +08:00
    求关注,都没遇到过这问题么?
    tysx
        2
    tysx  
       2014-12-25 11:11:27 +08:00
    完整代码呢?
    aeshfawre
        3
    aeshfawre  
    OP
       2014-12-25 14:02:55 +08:00
    这个代码已经就是完整的了,import 和func main就这两行省略了,还一行 m.run
    我这里做了点分析. 发送数据包是用火车头里面的那个httppostget程序.
    在win7 64系统中发送post包,martini这边的处理时间就会200多ms
    在虚拟机的xp系统中发送post包,处理时间就是正常的,

    用httpdebugger截取了两个系统中发送的post包,是一模一样的,没区别.

    所以我猜测可能是多出来的时间是发生在发起http连接的步骤中,具体怎么样的原因就不清楚了.
    可能只是httppostget这个程序的坑吧,只是这样猜测.
    这个问题影响不大.结贴
    lyric
        4
    lyric  
       2014-12-25 15:05:17 +08:00   ❤️ 1
    OS X 下差不多的性能,非 Product 环境

    [martini] Started GET /echo for 127.0.0.1:50571
    [martini] Completed 200 OK in 151.042us
    [martini] Started POST /echo for 127.0.0.1:50572
    [martini] Completed 200 OK in 254.716us
    datou552211
        5
    datou552211  
       2014-12-25 16:27:30 +08:00   ❤️ 1
    难道在post里面做了crsf验证
    aeshfawre
        6
    aeshfawre  
    OP
       2014-12-25 18:25:28 +08:00
    @lyric 你那里的get和post的处理时间相差不大的,我这里的是差了很多.可能只是我这里发送post包的程序有点问题
    aeshfawre
        7
    aeshfawre  
    OP
       2014-12-25 18:27:12 +08:00
    @datou552211 没弄那个的
    defia
        8
    defia  
       2014-12-28 21:27:56 +08:00   ❤️ 1
    @aeshfawre 你可以用 http://gin-gonic.github.io/gin/ 这个框架试试 martini比较慢的。。
    aeshfawre
        9
    aeshfawre  
    OP
       2014-12-28 23:34:01 +08:00
    @defia 十分感谢,martini框架搜到的次数更多点,gin这个还真没找到过.
    l3i2
        10
    l3i2  
       2015-01-23 10:17:34 +08:00
    @aeshfawre, 用PostFormValue替代FormValue试一下?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1171 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:38 · PVG 01:38 · LAX 10:38 · JFK 13:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.