{"action":"created","issue":{"url":"https://api.github.com/repos/gin-gonic/gin/issues/370","labels_url":"https://api.github.com/repos/gin-gonic/gin/issues/370/labels{/name}","comments_url":"https://api.github.com/repos/gin-gonic/gin/issues/370/comments","events_url":"https://api.github.com/repos/gin-gonic/gin/issues/370/events","html_url":"https://github.com/gin-gonic/gin/issues/370","id":94286415,"number":370,"title":"Performance of for loop and printing it's result in template","user":{"login":"vadimyer","id":10176730,"avatar_url":"https://avatars.githubusercontent.com/u/10176730?v=3","gravatar_id":"","url":"https://api.github.com/users/vadimyer","html_url":"https://github.com/vadimyer","followers_url":"https://api.github.com/users/vadimyer/followers","following_url":"https://api.github.com/users/vadimyer/following{/other_user}","gists_url":"https://api.github.com/users/vadimyer/gists{/gist_id}","starred_url":"https://api.github.com/users/vadimyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vadimyer/subscriptions","organizations_url":"https://api.github.com/users/vadimyer/orgs","repos_url":"https://api.github.com/users/vadimyer/repos","events_url":"https://api.github.com/users/vadimyer/events{/privacy}","received_events_url":"https://api.github.com/users/vadimyer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-10T11:09:23Z","updated_at":"2015-07-10T16:11:09Z","closed_at":null,"body":"I'm new to Go and gin-gonic (so far, not even a programmer) so excuse my ignorance if this is a simple question and I make something wrong.\r\n\r\nI've created a slice, filled it through for loop and pushed the slice to template:\r\n```go\r\na := make([]int, 1000)\r\nfor i := 0; i < 1000; i++ {\r\n        a[i] = i\r\n}\r\n\r\nc.HTML(http.StatusOK, \"index.tmpl\", gin.H{\r\n        \"a\": a,\r\n})\r\n```\r\n\r\nindex.tmpl:\r\n```{{ range .a }} {{ . }} {{ end }}```\r\n\r\nI'm comparing performance with php. I used to test my php scripts with loader.io, pushing 5k/s of concurrent connections for 1 minute. In php, the for loop is almost the same thing, I create an array, make a loop, push each iteration into it, and then pass the array to template, where I just foreach the array and receive the same result.\r\n\r\nBut performance in case of php is, well, better. I get more successful responses (over 25-30k) for a 1 min period, while my gin/go app is breaking after 1000-1500 successful responses.\r\n\r\nNotes: I'm using the same configuration of PCs and other software, nginx as front-end server."},"comment":{"url":"https://api.github.com/repos/gin-gonic/gin/issues/comments/120447607","html_url":"https://github.com/gin-gonic/gin/issues/370#issuecomment-120447607","issue_url":"https://api.github.com/repos/gin-gonic/gin/issues/370","id":120447607,"user":{"login":"manucorporat","id":127379,"avatar_url":"https://avatars.githubusercontent.com/u/127379?v=3","gravatar_id":"","url":"https://api.github.com/users/manucorporat","html_url":"https://github.com/manucorporat","followers_url":"https://api.github.com/users/manucorporat/followers","following_url":"https://api.github.com/users/manucorporat/following{/other_user}","gists_url":"https://api.github.com/users/manucorporat/gists{/gist_id}","starred_url":"https://api.github.com/users/manucorporat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manucorporat/subscriptions","organizations_url":"https://api.github.com/users/manucorporat/orgs","repos_url":"https://api.github.com/users/manucorporat/repos","events_url":"https://api.github.com/users/manucorporat/events{/privacy}","received_events_url":"https://api.github.com/users/manucorporat/received_events","type":"User","site_admin":false},"created_at":"2015-07-10T16:11:09Z","updated_at":"2015-07-10T16:11:09Z","body":"@vadimyer if you use FasCGI, then it is probably not the same configuration.\r\nif your server multi-core?\r\n\r\n1. If Gin is running in debug mode. I will reload from disk and parse the template from scratch for everysingle request.\r\n2. Have you changed runtime.GOMAXPROCS()? by default Go runtime will only use a single CPU thread, since you performance test is highly concurrent and the \r\n3. Make sure the Go program have enough file descriptors to handle 5k concurrent open sockets. Raise the ulimit (use a conservative value). Probably 25.000\r\n4. A simple PHP code using HHVM can run very very fast.\r\n\r\nAdd this code before initializing the gin router:\r\n\r\n```go\r\n\truntime.GOMAXPROCS(runtime.NumCPU())\r\n\tgin.SetMode(gin.ReleaseMode)\r\n```"}}