FAQ
Hi,everyone:
    I want to perform a stress test.

    When a client start,it get a token through http connection(then
close),then establish a tcp connection to the server and login.After a
client login,I start a ticker for heartBeat,code like this:

var end = make(chan int, 1)
func main() {
     for i := 1; i < 50000; i++ {
         time.Sleep(time.Millisecond * 5)
         go clientLogin(uint64(i))
      }
    <-end
}

func clientLogin(num uint64, addr string) {
   client, err := client.NewClient(num)
   client.GetToken() //getToken through http
connection
   client.Login() //establish a TCP
connection and login
   heartbeat := time.NewTicker(time.Second * 300) //heartbeat per 5 minutes
   for {
     select {
     case <-ping.C:
         client.HeartBeat()
       }
   }
}
I run this code on a a 12 cores server,when 10k clients login successfully
  the CPU cost 1000%,and after 20k clients,I can only login 3~5 clients per
second.
profile:
Showing top 15 nodes out of 63 (cum >= 4.85s)
       flat flat% sum% cum cum%
     21.89s 9.84% 9.84% 128.32s 57.71% net.(*netFD).Read
     17.58s 7.91% 17.75% 40.28s 18.11% runtime.exitsyscall
     15.79s 7.10% 24.85% 15.79s 7.10% runtime.newdefer
     12.96s 5.83% 30.68% 151.41s 68.09%
  test_frame/connection.(*ServerConn).readBytes
     11.27s 5.07% 35.75% 23.35s 10.50% runtime.reentersyscall
     10.45s 4.70% 40.45% 82.77s 37.22% syscall.Syscall
      9.38s 4.22% 44.67% 9.38s 4.22% runtime.deferproc_m
      9.17s 4.12% 48.79% 12.73s 5.72% exitsyscallfast
      8.03s 3.61% 52.40% 11.86s 5.33% runtime.casgstatus
      7.66s 3.44% 55.85% 7.66s 3.44% runtime.cas
      7.59s 3.41% 59.26% 7.59s 3.41% runtime.onM
      6.42s 2.89% 62.15% 134.74s 60.60% net.(*conn).Read
      6.31s 2.84% 64.98% 6.31s 2.84% runtime.writebarrierptr
      6.26s 2.82% 67.80% 32.09s 14.43% runtime.entersyscall
      4.85s 2.18% 69.98% 4.85s 2.18% save

vmstat command :
  procs -----------memory---------- ---swap-- -----io---- --system--
-----cpu-----
  r b swpd free buff cache si so bi bo
in cs us sy id wa st
15 0 50064 23193676 248988 3122364 0 0 0 18 0 0 3 4
93 0 1
14 0 50064 23191820 248988 3122388 0 0 0 120 55194 98623 9
91 0 0 0
20 0 50064 23192648 248988 3122404 0 0 0 80 48889 88842 8
90 0 0 1
25 0 50064 23193260 248988 3122416 0 0 0 32 55180 95249 9
89 0 0 2
29 0 50064 23193160 248992 3122428 0 0 0 136 57011 97290 9
89 0 0 1
18 0 50064 23193392 248992 3122448 0 0 0 0 54523 95895 9
87 0 0 4
20 0 50064 23193408 248992 3122452 0 0 0 140 48155 92503 10
84 0 0 6
34 0 50064 23195272 248992 3122468 0 0 0 132 47708 91636 10
86 0 0 5
13 0 50064 23196080 248992 3122480 0 0 0 28 43058 82809 9
87 0 0 4
18 0 50064 23196164 248996 3122500 0 0 0 160 40201 84010 8
89 0 0 3
23 0 50064 23195284 248996 3122484 0 0 0 220 39912 81084 8
89 0 0 3
32 0 50064 23190336 248996 3122488 0 0 0 56 42501 86995 9
82 0 0 9
14 0 50064 23195200 248996 3122512 0 0 0 132 42127 84646 9
84 0 0 7
33 0 50064 23195840 248996 3122548 0 0 0 272 43454 87183 9
90 0 0 0
29 0 50064 23195680 249000 3122556 0 0 0 272 43159 87298 9
88 0 0 2

mpstatl command:
12:55:23 PM CPU %usr %nice %sys %iowait %irq %soft %steal
  %guest %idle
12:55:24 PM all 10.74 0.25 88.76 0.00 0.00 0.08
  0.17 0.00 0.00
12:55:24 PM 0 10.00 0.00 90.00 0.00 0.00 0.00
  0.00 0.00 0.00
12:55:24 PM 1 8.08 0.00 91.92 0.00 0.00 0.00
    0.00 0.00 0.00
12:55:24 PM 2 13.86 0.00 83.17 0.00 0.00 0.99
  1.98 0.00 0.00
12:55:24 PM 3 10.00 0.00 90.00 0.00 0.00 0.00
  0.00 0.00 0.00
12:55:24 PM 4 9.00 0.00 91.00 0.00 0.00 0.00
    0.00 0.00 0.00
12:55:24 PM 5 9.09 0.00 90.91 0.00 0.00 0.00
  0.00 0.00 0.00
12:55:24 PM 6 7.00 0.00 93.00 0.00 0.00 0.00
  0.00 0.00 0.00
12:55:24 PM 7 13.00 0.00 87.00 0.00 0.00 0.00
  0.00 0.00 0.00
12:55:24 PM 8 7.92 0.99 91.09 0.00 0.00 0.00
  0.00 0.00 0.00
12:55:24 PM 9 7.00 0.00 93.00 0.00 0.00 0.00
  0.00 0.00 0.00
12:55:24 PM 10 16.00 1.00 83.00 0.00 0.00 0.00
  0.00 0.00 0.00
12:55:24 PM 11 17.17 0.00 82.83 0.00 0.00 0.00
  0.00 0.00 0.00

It seems that sockets interrupts cost most CPU ,CPU not enough.How can i
optimize the code to improve performance:
   1.login quickly
   2.hold as many as possible TCP connections,such as 100K
(Do 50K tickers cost many CPU resource? Should I reduce the number of
tickers?)


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Dave Cheney at Mar 11, 2016 at 5:51 am
    Can you paste the svg view of your trace please.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Approaching at Mar 11, 2016 at 6:04 am
    Thanks Dave,here is the svg.

    在 2016年3月11日星期五 UTC+8下午1:51:11,Dave Cheney写道:
    Can you paste the svg view of your trace please.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Dave Cheney at Mar 11, 2016 at 6:36 am
    It looks like a lot of (possibly small) reads are falling through to the
    network. Maybe adding bufio.Reader would help.
    On Friday, 11 March 2016 17:04:38 UTC+11, appro...@codinglife.me wrote:

    Thanks Dave,here is the svg.

    在 2016年3月11日星期五 UTC+8下午1:51:11,Dave Cheney写道:
    Can you paste the svg view of your trace please.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Approaching at Mar 11, 2016 at 9:07 am
    Hi,Dave:
        Thank you vey much.I followed your suggestion,and the problem
      solved.Thanks!


    在 2016年3月11日星期五 UTC+8下午2:35:57,Dave Cheney写道:
    It looks like a lot of (possibly small) reads are falling through to the
    network. Maybe adding bufio.Reader would help.
    On Friday, 11 March 2016 17:04:38 UTC+11, appro...@codinglife.me wrote:

    Thanks Dave,here is the svg.

    在 2016年3月11日星期五 UTC+8下午1:51:11,Dave Cheney写道:
    Can you paste the svg view of your trace please.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 11, '16 at 5:39a
activeMar 11, '16 at 9:07a
posts5
users2
websitegolang.org

2 users in discussion

Approaching: 3 posts Dave Cheney: 2 posts

People

Translate

site design / logo © 2022 Grokbase