C++博客-金庆的专栏 http://www.598club.com/jinq0123/zh-cnThu, 20 Feb 2020 15:36:00 GMTThu, 20 Feb 2020 15:36:00 GMT60C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2020/02/13/217125.html???o????o?Thu, 13 Feb 2020 06:38:00 GMThttp://www.598club.com/jinq0123/archive/2020/02/13/217125.htmlhttp://www.598club.com/jinq0123/comments/217125.htmlhttp://www.598club.com/jinq0123/archive/2020/02/13/217125.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/217125.htmlhttp://www.598club.com/jinq0123/services/trackbacks/217125.html# ??go??????????????o??????
(???o?????????? 2020.2)

golang ??-??????????|???????

```
type Writer interface {
    Write func(p []byte) (n int, err error)
}
```

?????API?????|????????a??????????????????????a??????????????|? io.Copy() ??|???????????a Writer ??? Reader???
```
func Copy(dst Writer, src Reader) (written int64, err error)
```

????????????2??a?????????????
```
func CopyWithFunc(writeFunc func([]byte) (int, error), readRunc func([]byte) (int, error)) (written int64, err error)
```

????????????????????????????????????????????????????????????????????API???????????
?|? io.Copy() ???2??a?????????|????|??????????????????????????????????????????4??a Copy() ???????
golang ?2??????????????a????4??a????????????????????

??????????????-?????|????????????????????????????????? io.Copy().
?|?????????a?????:
```
func MyWriteFunction(p []byte) (n int, err error) {
    fmt.Print("%v",p)
    return len(p),nil
}
```
??? io.Copy() ?????|??????o?????a Writer????1??????????????????????oWriter???????????
?????? `WriteFunc` ?????????? Writer???

```
type WriteFunc func(p []byte) (n int, err error)

func (wf WriteFunc) Write(p []byte) (n int, err error) {
    return wf(p)
}
```

WriteFunc ???o??????a??? MyWriteFunction ????????????????????????????????????o? Writer ?????????
?????? MyWriteFunction ????????'????????WriteFunc??????????o?????a Writer.
?????????????? io.Copy() ?o????

```
io.Copy(WriteFunc(MyWriteFunction), strings.NewReader("Hello world"))
```

????????http://stackoverflow.com/questions/20728965/golang-function-pointer-as-a-part-of-a-struct

???o? 2020-02-13 14:38 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2020/01/08/217067.html???o????o?Wed, 08 Jan 2020 11:46:00 GMThttp://www.598club.com/jinq0123/archive/2020/01/08/217067.htmlhttp://www.598club.com/jinq0123/comments/217067.htmlhttp://www.598club.com/jinq0123/archive/2020/01/08/217067.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/217067.htmlhttp://www.598club.com/jinq0123/services/trackbacks/217067.html
(???o?????????? 2020.1)

golang ???o???-???????? DATA RACE, ??? chan ??3?-??????????2?a????

==================
WARNING: DATA RACE
Write at 0x00c000098010 by goroutine 68:
  runtime.closechan()
      /usr/lib/golang/src/runtime/chan.go:327 +0x0
  valky/common/tcp.(*Session).Close()
      /var/tmp/src/f4f4f712-7894-4d98-83dd...
  valky/common/tcp.(*Session).recvloop()
      /var/tmp/src/f4f4f712-7894-4d98-83dd...

Previous read at 0x00c000098010 by goroutine 100:
  runtime.chansend()
      /usr/lib/golang/src/runtime/chan.go:140 +0x0
  valky/common/tcp.(*Session).Send()
      /var/tmp/src/f4f4f712-7894-4d98-83dd...
  main.(*Role).sendMsg()
      /var/tmp/src/f4f4f712-7894-4d98-83dd...
==================
Found 1 data race(s)

????o??????? chan ??3?-????-????????3??????????o?????????????|???????????????
[How to Gracefully Close Channels](http://go101.org/article/channel-closing.html)

?????-?????o???chan ???????3?-????????????3?-??? chan ???????????????? panic.
???????? DATA RACE ???o??1???????2???? panic???

chan ??3?-?????????????????????|????????????????-??3?-????1????????|???????????a??????????????|???3?-chan?o????

????????DATA RACE ??????????????????-??3?-chan.

?????-?|????????o?o???????1?????3?-chan.
?|?????2???'??1???????????'????????a recover. ????????1????????|?????????????????????????3?-???



???o? 2020-01-08 19:46 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2019/12/16/217028.html???o????o?Mon, 16 Dec 2019 10:03:00 GMThttp://www.598club.com/jinq0123/archive/2019/12/16/217028.htmlhttp://www.598club.com/jinq0123/comments/217028.htmlhttp://www.598club.com/jinq0123/archive/2019/12/16/217028.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/217028.htmlhttp://www.598club.com/jinq0123/services/trackbacks/217028.html
(???o?????????? 2019.12)

?????????????????a??????????'??o????breakpad ????????? minidump ????o??????????????o?????????????1????????????????-????????

????????????????????|?????o???????????????????????????????????????????????????1?????????-??????????????1????????o????

???????????????????????????????????a??1??? GM ????? 200 ?????????o????????????????????????? 100 ????????o?????
?????????????????????????????????????????????????????????????'?????3?????|?????????????????-??????????'?????????|??????

??o????1?????? `boost::property_tree::ini_parser::read_ini()` ??-????|???????

```
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `./GMServer.dbg'.
Program terminated with signal 11, Segmentation fault.
#0  0x00000000010ca227 in tcmalloc::SLL_Next(void*) ()
Missing separate debuginfos, use: debuginfo-install glibc-2.17-105.el7.x86_64 libgcc-4.8.5-4.el7.x86_64 libstdc++-4.8.5-4.el7.x86_64 zlib-1.2.7-15.el7.x86_64
(gdb) bt
#0  0x00000000010ca227 in tcmalloc::SLL_Next(void*) ()
#1  0x00000000010ca2b8 in tcmalloc::SLL_TryPop(void**, void**) ()
#2  0x00000000010ca715 in tcmalloc::ThreadCache::FreeList::TryPop(void**) ()
#3  0x00000000011ebe6c in tc_newarray ()
#4  0x00007efddb7d4c69 in std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) () from /lib64/libstdc++.so.6
#5  0x0000000000a18153 in std::string::_S_construct<char*> (__beg=0x3f6c8b9 "LobbyServer]", __end=0x3f6c8c4 "]", __a=...) at /usr/include/c++/4.8.2/bits/basic_string.tcc:138
#6  0x00007efddb7d641c in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&, unsigned long, unsigned long) ()
   from /lib64/libstdc++.so.6
#7  0x00007efddb7d6462 in std::string::substr(unsigned long, unsigned long) const () from /lib64/libstdc++.so.6
#8  0x0000000000a3c3be in boost::property_tree::ini_parser::read_ini<boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> > > (stream=..., pt=...)
    at /var/tmp/src/f4f4f712-7894-4d98-83dd-b91be8e0555e/Linux-Debug/003_servers/../000_BaseLib/3RdParty/boost/include/boost/property_tree/ini_parser.hpp:111
#9  0x0000000000a3b2f0 in boost::property_tree::ini_parser::read_ini<boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> > > (
    filehelp="cfg.ini", pt=..., loc=...)
    at /var/tmp/src/f4f4f712-7894-4d98-83dd-b91be8e0555e/Linux-Debug/003_servers/../000_BaseLib/3RdParty/boost/include/boost/property_tree/ini_parser.hpp:169
...
#27 0x00007efddba27dc5 in start_thread () from /lib64/libpthread.so.0
#28 0x00007efddaf341cd in clone () from /lib64/libc.so.6
(gdb) q
```

?????? property_tree ?????????????????????o????????????????????????????
??????????????? uWS ?????HTTP ???????? hiredis ????? Redis???
???o??o??????????????-????????????????????a??????????????????o?????3????????????????????????????????????????a??????o??????3????????????

?????????????????????????????a?????????????????????????
?????o uWS ??-?????o??????a?????a????1?????????????????a new/delete ???????????1?????o????-????????????1????????a??????????|?-?????????????
????????????????-???????

???????????????????????|????????o????

|????????? -fstack-protector-all ?????????????????a???????????????o?|???????o??????????????????????????????????????????????'??????
?????????a????1??????????????????????????????????ao???????????|??????????|??????a?????????????????????o 0x5a, ???????????????????????o 0xcc.
?'??o????????????????????-????????-???????

?????????????a Address Sanitizer, ??a??|??????????????1 -fsanitize=address ??3??????
?????????????????????-??????|?-??????3??????????
??????????a???????? tcmalloc ????????????|???'??1????????????????????????? asan ?o????????o????????????????o????
?|?????-??? tcmalloc ???????????????????????'??o????

??????????????????????????? "double-free" ???????
```
[jinqing@host-192-168-21-31 bin]$ gdb GMServer.dbg
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/jinqing/valkyrie/Runtime_ZT_QA/bin/GMServer.dbg...done.
(gdb) r
Starting program: /home/jinqing/valkyrie/Runtime_ZT_QA/bin/GMServer.dbg
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
iLogLevel:1
[New Thread 0x7ffff3724700 (LWP 1010)]
[New Thread 0x7ffff2c1d700 (LWP 1011)]
[New Thread 0x7ffff2116700 (LWP 1012)]
[New Thread 0x7ffff160f700 (LWP 1013)]
[New Thread 0x7ffff0b08700 (LWP 1014)]
=================================================================
==1005== ERROR: AddressSanitizer: attempting double-free on 0x6004000270d0:
    #0 0x7ffff4e60dd9 (/usr/lib64/libasan.so.0.0.0+0x15dd9)
    #1 0x1570e8d (/home/jinqing/valkyrie/Runtime_ZT_QA/bin/GMServer.dbg+0x1570e8                                                                                                         d)
0x6004000270d0 is located 0 bytes inside of 5-byte region [0x6004000270d0,0x6004                                                                                                         000270d5)
freed by thread T0 here:
    #0 0x7ffff4e60dd9 (/usr/lib64/libasan.so.0.0.0+0x15dd9)
    #1 0x1570e8d (/home/jinqing/valkyrie/Runtime_ZT_QA/bin/GMServer.dbg+0x1570e8                                                                                                         d)
previously allocated by thread T0 here:
    #0 0x7ffff4e60ef9 (/usr/lib64/libasan.so.0.0.0+0x15ef9)
    #1 0x157179e (/home/jinqing/valkyrie/Runtime_ZT_QA/bin/GMServer.dbg+0x157179                                                                                                         e)
Thread T4 created by T0 here:
    #0 0x7ffff4e55a0a (/usr/lib64/libasan.so.0.0.0+0xaa0a)
    #1 0x13fc796 (/home/jinqing/valkyrie/Runtime_ZT_QA/bin/GMServer.dbg+0x13fc79                                                                                                         6)
==1005== ABORTING
[Thread 0x7ffff160f700 (LWP 1013) exited]
[Thread 0x7ffff2116700 (LWP 1012) exited]
[Thread 0x7ffff2c1d700 (LWP 1011) exited]
[Thread 0x7ffff3724700 (LWP 1010) exited]
[Thread 0x7ffff7fe77c0 (LWP 1005) exited]
[Inferior 1 (process 1005) exited with code 01]
Missing separate debuginfos, use: debuginfo-install glibc-2.17-105.el7.x86_64 li                                                                                                         basan-4.8.5-39.el7.x86_64 libgcc-4.8.5-4.el7.x86_64 libstdc++-4.8.5-4.el7.x86_64                                                                                                          zlib-1.2.7-15.el7.x86_64
(gdb)
```

?????o???o? gcc 4.8, ??????asan?2????????????????o???gcc 4.9 ??????????????????????o????
?????????|??'????? nm ??????????????????????

```
[jinqing@host-192-168-21-31 bin]$ nm GMServer.dbg | grep 1570e
0000000001570e50 T freeReplyObject
0000000001570ef0 T redisReaderFree
[jinqing@host-192-168-21-31 bin]$ nm GMServer.dbg | grep 15717
0000000001571750 t createStringObject
[jinqing@host-192-168-21-31 bin]$ nm GMServer.dbg | grep 13fc7
00000000013fc700 t _ZN5boost6detail23set_current_thread_dataEPNS0_16thread_data_baseE
00000000013fc7d0 T _ZN5boost6thread21start_thread_noexceptERKNS_17thread_attributesE
00000000013fc750 T _ZN5boost6thread21start_thread_noexceptEv
00000000013fc740 T _ZN5boost6threadC1Ev
00000000013fc740 T _ZN5boost6threadC2Ev
[jinqing@host-192-168-21-31 bin]$ ^C
```

????o??o freeReplyObject() ?????o "double-free".

????o?????a????o????????????????????o????????????? uWS ???????????? new/delete ?????1????????????
Redis ?1??????a delete ???????????3???????? ReplyObject ??|???? freeReplyObject().
??'???????'?????????????o?????a???????? freeReplyObject.

????????? ReplyObject ????-???o?????a???????????????????? Redis ?????????????????|???? freeReplyObject() ?1???????????????o??o???
???????????????????-?1????????-???????????????o?????? freeReplyObject().
???????????a??? 60s ????????????? Ping ?????????????o? freeReplyObject(), ???????2?????????o???
?????? GM ??????1?|????o??????? Redis ??1???????????????????o? freeReplyObject()???

?-???????????3???????????????????????????????????'????????????o????????????????????????????????????????????????????????????1??????
??o?o?????1???????????????????????o??????????????????????o????????o??????o????
??????????????-??? freeReplyObject() ????2????|?????????1?????-?????????o??o???

???o???????????????????????????????????????????o???o?????|???????????????????o????? Ping ?'??????????????????o???|?????????????o????
???-?????????????1?2??????1?????-??o????


???o? 2019-12-16 18:03 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2019/09/26/216860.html???o????o?Thu, 26 Sep 2019 09:19:00 GMThttp://www.598club.com/jinq0123/archive/2019/09/26/216860.htmlhttp://www.598club.com/jinq0123/comments/216860.htmlhttp://www.598club.com/jinq0123/archive/2019/09/26/216860.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/216860.htmlhttp://www.598club.com/jinq0123/services/trackbacks/216860.html
(???o?????????? 2019.9)

??????????-???????????????core??????????????????????
?????? std::thread ?-??o?????-??????????????? core ????????????????|???????

```
Program received signal SIGABRT, Aborted.
[Switching to Thread 0x7f18f00ab700 (LWP 32340)]
0x00007f19007335f7 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x00007f19007335f7 in raise () from /lib64/libc.so.6
#1  0x00007f1900734ce8 in abort () from /lib64/libc.so.6
#2  0x00007f19010379d5 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6
#3  0x00007f1901035946 in ?? () from /lib64/libstdc++.so.6
#4  0x00007f1901035973 in std::terminate() () from /lib64/libstdc++.so.6
#5  0x00007f190108c2b5 in ?? () from /lib64/libstdc++.so.6
#6  0x00007f19012e7dc5 in start_thread () from /lib64/libpthread.so.0
#7  0x00007f19007f41cd in clone () from /lib64/libc.so.6
(gdb)
```

????????????????????3????????????1???

????' GCC 8 ????-??o??????????

????????
* [C++ uncaught exception in worker thread](http://stackoverflow.com/questions/48535100/c-uncaught-exception-in-worker-thread)
* [Bug 55917 - Impossible to find/debug unhandled exceptions in an std::thread](http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55917)


???o? 2019-09-26 17:19 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2019/09/20/216848.html???o????o?Fri, 20 Sep 2019 06:45:00 GMThttp://www.598club.com/jinq0123/archive/2019/09/20/216848.htmlhttp://www.598club.com/jinq0123/comments/216848.htmlhttp://www.598club.com/jinq0123/archive/2019/09/20/216848.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/216848.htmlhttp://www.598club.com/jinq0123/services/trackbacks/216848.html
(???o?????????? 2019.9)

svn rename ?????a???????1???'??1?????1???????o????????2???????????
?|???? svn rename ????????1?????1????????3????o???????????????-???????????2???
????????1?????????????????o?????????????o?????????

git ??1??????o????o?????????????????1????????????????????????????????'??1?a???1????????-??o?????


???o? 2019-09-20 14:45 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2019/04/20/216361.html???o????o?Sat, 20 Apr 2019 02:52:00 GMThttp://www.598club.com/jinq0123/archive/2019/04/20/216361.htmlhttp://www.598club.com/jinq0123/comments/216361.htmlhttp://www.598club.com/jinq0123/archive/2019/04/20/216361.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/216361.htmlhttp://www.598club.com/jinq0123/services/trackbacks/216361.html
(???o?????????? 2019.4)

See: http://github.com/golang/go/issues/29621

????? consul ?3???????????????????? consul ??? DNS ???????????????????????
?????? golang ??'?? 1.12 ???????? Windows ???????3???????a????1???? DNS ??????????1?????2??????????????????

????|??????o 127.0.0.1 ??? consul, ?3??? myservice:8888 ?????????
consul DNS ??????????????o 8600.

grpc ??? Dial() ???????????????a dns ?????????????? grpc.Dial() ?? Linux ??o????????????????? Windows ????'????

conn, err := grpc.Dial("dns://127.0.0.1:8600/myservice.service.consul:8888", ...)


???o? 2019-04-20 10:52 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2019/04/04/216338.html???o????o?Thu, 04 Apr 2019 09:57:00 GMThttp://www.598club.com/jinq0123/archive/2019/04/04/216338.htmlhttp://www.598club.com/jinq0123/comments/216338.htmlhttp://www.598club.com/jinq0123/archive/2019/04/04/216338.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/216338.htmlhttp://www.598club.com/jinq0123/services/trackbacks/216338.html
?o??????[Replace protobuf CopyFrom with assignment](http://github.com/tensorflow/tensorflow/commit/9501c4104125fb8c2c2d2e837fc2dd8a24034d52)

protobuf ????????? C++ ????????-????????o CopyFrom() ?????????????????? Message ?????o????????
????????????????2??a?????????????????????1??'????????

```
  void CopyFrom(const ::google::protobuf::Message& from) final;
  void CopyFrom(const PlayerData& from);
```

??????????????????????????????-???????

```
class PlayerData : public ::google::protobuf::Message {
 public:
  ...
  inline PlayerData& operator=(const PlayerData& from) {
    CopyFrom(from);
    return *this;
  }
  #if LANG_CXX11
  inline PlayerData& operator=(PlayerData&& from) noexcept {
    ...
  }
  #endif
```

????????????'???????????????????
```
error: no match for ‘operator=’ (operand types are ‘a::PlayerData’ and ‘a::HeroInfo’)
```

??????a????o????1'??? CopyFrom() ????????????????????

???o? 2019-04-04 17:57 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2019/01/31/216228.html???o????o?Thu, 31 Jan 2019 02:21:00 GMThttp://www.598club.com/jinq0123/archive/2019/01/31/216228.htmlhttp://www.598club.com/jinq0123/comments/216228.htmlhttp://www.598club.com/jinq0123/archive/2019/01/31/216228.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/216228.htmlhttp://www.598club.com/jinq0123/services/trackbacks/216228.html

# open-match??1???????


(???o?????????? 2019.1)

http://github.com/GoogleCloudPlatform/open-match

open-match ????????a???????????????1???????????
???????????????a????1??????1??????3???????docker??????????1???????????????

?????o????a???????????????1??'???o??????a redis.

* ??????, ?????????????????? redis???????????????????????????'????????
* ??????????????????????????????1??????????????????'????????
* MMFOrc??????????1??????3?(MMF)
* MMF, ?a????1???1??????3????????? redis ???????????????1??????????????????????? redis. ?????1????????????o???

???????????-????? open-match ?????????????????????????????????????o frontendclient ??? Director???
????????2?????????????????????????????o??????1???????????
Director ????????????????1?????????????????????????a????????a?????1???oo???????.
Director ??|???o?????a??1?????????'????????????????????????'????????
????????????'??????????? redis, ???????????????????????'?????????????? frontendclient????????????????????'???

## test/cmd/frontendclient


?????????????????????????????????????API, ?????1????????/????????????????????????????'???(DGS)????????(Assignment)???

Player ????????????????a?????????????-ID?-???????????o???????????????aID.
???????????????????? Player, CreatePlayer() ???????o??'??a?????????? GetUpdates() ?????????????a?????????

main() ??-?????o????a??????????????a????????? GetUpdates() ????????????????go waitForResults() ??-??????????????
waitForResult() ??????????-?????1????????????????? resultsChan???????????? resultsChan ??????o????????????
????????????????1??? g ????????-???????????? CreatePlayer() ?????1?????

cleanup() ??? DeletePlayer() ?????????1??????????????????????'??a?????????1???|??????????a?????????

??????????????????????2??????1????1????o?????? resultChan ??-???? Assignment, ?1?????????? udpClient().

????o????o?????????????? frontend.proto

## examples/backendclient


MatchObject.Properties ?????? testprofile.json ????????????o?????1?????o Profile ?????|??'?????1???
pbProfile ??? MatchObject???Profile ?-?????o? MatchObject?
Profile ???????1???? MMF ??????????????????????
`pbProfile.Properties = jsonProfile` ?????o?2?????

ListMatches()?????o????aProfile???????????1?????
??????????a??1????????????CreateAssignments()??????'????????, ???o Assignment, ??????????????????????????????

## cmd/frontendapi


CreatePlayer() ?? Player ??1??????? redis, ???????o Player.Id, ???????o HSET???
??1 Player ????????a attribute?????????? ZSET ??-??????
?-?? Player ??????????????????

GetUpdates() ?????2s?????redis, Player???????????????????????????-?? Player ????????a?????????

?|????CreatePlayer()??-???????a????????a?????????
????????????Player???GetUpdates()??-?????????????????????????aredis?????

## cmd/backendapi


CreateMatch() ??- profile ???????o MatchObject, ????????a??????????????????????
profile ????????? redis, ????o profile.Id.
`requestKey := xid() + "." + profile.Id`,
?1??? requestKey ?????? redis ????? "profileq"???
?????????2s????? redis, ????????|??? requestKey ????o??????1??????????????

ListMatch() ???2s????????? CreateMatch().

DeleteMatch() ?????????? Id ????a?????

CreateAssignments() ??o????a??????????Assignment, ??3????'????????
???????????Roster??-???Player??1??????redis??-?????Assignment.
(Assignment ??'??1?????????|???????????'?????)
???????? Player.Id ??? "proposed" ???? "deindexed"?????????a??? ZSET, ????????o??????????'???
Roster ?o?????????????-???????????|??o???1???????1????????a??????-??????????a????????

DeleteAssignments() ????????????????? Player ??1???????? Assignment ?-???????

## cmd/mmforc


??1???????????? mmforc (matchmaking function orchestrator) ???????????

mmforc ???????? redis ??? profileq ??-?????o 100 ??a??????, ?????- profileq ?????aset????????
????????????o`SPOP profileq 100`.

??1?????a profile, ?????o?????a k8s ?????????

```
    // Kick off the job asynchrnously
    go mmfunc(ctx, profile, cfg, defaultMmfImages, clientset, &pool)
```

?????10s, ?????????????1????????????????????????|? `checkProposals`, ??3?????o evaluator ?????????

profileq ??-???????'? profile ??o?-???|??2???matchObjectID.profileID???
??? profileID ??o?????????????? redis ????? profile ????????1, profile ?????a MatchObject ??1????

profile ????????1??o json ??2????????- "jsonkeys.mmfImages" ??o mmf (matchmaking function) ????????

?|????profile??????'????????? mmfImages ??o??o?????????????????????????mmfImages ??a????????????????a????????

???? MMF_* ???????????????????????????.

## mmf


?o??????examples\functions\golang\manual-simple

?????????????? "MMF_PROFILE_ID" ??????o profileID, ?1???? redis ?????(HGETALL) profile???HSET ????????

??? profile ??-??? pools ?-?????????3??1???????????
pools ?????o????a pool, ?????a pool ??-???????a filter, ?????a filter ??? redis ?????|?????? Player.

profile ???????????-???????

* "properties.playerPool"
  json??2??????????o???????????????|?“mmr: 100-999”
* "properties.roster"
  json??2, ???????a????????????|? “red: 4”

?o???????`examples\backendclient\profiles\testprofile.json`

### ????????1??????


simple mmf ?????1???????|???????

1. ??? redis ????? profile???????????????????????????????
1. ?????a????????????? redis ????????????????????????o????o???????????
1. ???? ignoreList, ??3????? 800s ????2??1??????????????????????3 proposal ??? deindexed ZSET ???????
1. ?|?????????????????a???a???????? insufficient_players ?1?????o
1. ??????????a???????????
1. ??? redis ??????????

### ??????


profile ??-????? roster?????3???????????????????????-???? prososalKey.
????-??????????????????????????????
????????? "proposalq" ????? prososalKey

### ?????


poolRosters ??? (pool???, filter attribute) ??o??????????o Player ID ????.
????-???? redis ??????????|???????????? Player ID.

overlaps ??? pool ?????o?????????-???|?????pool??-??????filter??? Player ID ??????????? ignore list.

rosters ??? profile ??-??? "properties.rosters" ?-?????????????????????
????? rosters, ??o?????a????????????aplayer???????1?o?pool???PlayerID, ????-??? mo.Rosters.
?????- profileRosters ???????2??????



???o? 2019-01-31 10:21 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/12/26/216141.html???o????o?Wed, 26 Dec 2018 02:07:00 GMThttp://www.598club.com/jinq0123/archive/2018/12/26/216141.htmlhttp://www.598club.com/jinq0123/comments/216141.htmlhttp://www.598club.com/jinq0123/archive/2018/12/26/216141.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/216141.htmlhttp://www.598club.com/jinq0123/services/trackbacks/216141.html???? go mod
(???o?????????? 2018.12)

Go 1.11 ?????? module.

???????????|??? GOPATH/src ????????????

????????????????????????? `go.mod`

E:\temp
λ mkdir -p testmod\hello

E:\temp
λ cd testmod\hello\

E:\temp\testmod\hello
λ go mod init github.com/jinq0123/hello
go: creating new go.mod: module github.com/jinq0123/hello


?????o `hello.go`

package main

import (
    "fmt"
    "rsc.io/quote"
)

func main() {
    fmt.Println(quote.Hello())
}


?????o?????? `golang.org/x/text` ???????????

E:\temp\testmod\hello
λ go build
go: golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c: unrecog
nized import path "golang.org/x/text" (https fetch: Get http://g
olang.org/x/text?go-get=1: dial tcp 216.239.37.1:443: connectex:
A socket operation was attempted to an unreachable network.)
go: error loading module requirements


`go.mod` ?????

replace golang.org/x/text => github.com/golang/text v0.3.0


???????????o????????o????

E:\temp\testmod\hello
λ go build
go: finding github.com/golang/text v0.3.0
go: downloading rsc.io/sampler v1.3.0
go: downloading github.com/golang/text v0.3.0

E:\temp\testmod\hello
λ hello.exe
Hello, world.


?|???????????????????????????????????

go.mod:9: replacement module without version must be directory path (rooted or starting with ./ or ../)


Go 1.11.1 replace ??????????????????????????????????????????????????? 1.11.4 ???????????

????????
http://github.com/golang/go/wiki/Modules


???o? 2018-12-26 10:07 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/11/26/216081.html???o????o?Mon, 26 Nov 2018 02:39:00 GMThttp://www.598club.com/jinq0123/archive/2018/11/26/216081.htmlhttp://www.598club.com/jinq0123/comments/216081.htmlhttp://www.598club.com/jinq0123/archive/2018/11/26/216081.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/216081.htmlhttp://www.598club.com/jinq0123/services/trackbacks/216081.html

grpc???TLS?????????????????


(???o?????????? 2018.11)

?? golang ?????o grpc ??????????????? TLS ??????????1????????????????
???????? C++ ??? golang ???????????o????????????????????????

????????
http://segmentfault.com/a/1190000007933303

????????


import (
    ...
    grpc_auth "github.com/grpc-ecosystem/go-grpc-middleware/auth"
    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials"
)

func main() {
    listen, err := net.Listen("tcp", ":12345")
    if err != nil {
        grpclog.Fatalf("failed to listen: %v", err)
    }
    
    // TLS???
    creds, err := credentials.NewServerTLSFromFile("keys/server.crt", "keys/server.key")
    if err != nil {
        grpclog.Fatalf("Failed to generate credentials %v", err)
    }
    
    // ?????????grpc Server, ?1???????TLS???
    s := grpc.NewServer(grpc.Creds(creds),
        grpc_auth.UnaryServerInterceptor(auth.Authenticate),
        grpc_auth.StreamServerInterceptor(auth.Authenticate))
    
    // ?3???HelloService
    pb.RegisterHelloServer(s, HelloService)
    grpclog.Println("Listen on " + Address + " with TLS")
    s.Serve(listen)
}

?????- server.key ??????????server.crt ????a?-???????1|????|?????????????

$ openssl genrsa -out server.key 2048
$ openssl req -new -x509 -sha256 -key server.key \
 -out server.crt -days 36500 \
 -subj /C=CN/ST=Shanghai/L=Songjiang/O=ztgame/OU=tech/CN=mydomain.ztgame.com/emailAddress=myname@ztgame.com

?????????1|??????
$ openssl x509 -in server.crt -noout -text


`auth.Authenticate` ?|????????????o interceptor, ??1?????a????????????a??????

package auth

import (
    "context"
    "sync"

    "google.golang.org/grpc/codes"
    "google.golang.org/grpc/metadata"
    "google.golang.org/grpc/status"
)

// from token.yaml file
var tokenToAppName = &sync.Map{}

func init() {
    tokenToAppName.Store("test", "test")
}

// XXX load tokenToAppName from file

// Authenticate checks that a token exists and is valid.
// It removes the token from the context and
//  stores the app name of the token in the returned context
func Authenticate(ctx context.Context) (context.Context, error) {
    token, err := extractHeader(ctx, "authorization-token")
    if err != nil {
        return ctx, err
    }
    // Remove token from headers from here on
    ctx = purgeHeader(ctx, "authorization-token")

    valAppName, ok := tokenToAppName.Load(token)
    if !ok {
        return ctx, status.Errorf(codes.Unauthenticated, "no app for token '%s'", token)
    }
    appName := valAppName.(string)
    return context.WithValue(ctx, keyAppName{}, appName), nil
}

func extractHeader(ctx context.Context, header string) (string, error) {
    md, ok := metadata.FromIncomingContext(ctx)
    if !ok {
        return "", status.Error(codes.Unauthenticated, "no headers in request")
    }

    authHeaders, ok := md[header]
    if !ok {
        return "", status.Error(codes.Unauthenticated, "no header in request")
    }

    if len(authHeaders) != 1 {
        return "", status.Error(codes.Unauthenticated, "more than 1 header in request")
    }

    return authHeaders[0], nil
}

func purgeHeader(ctx context.Context, header string) context.Context {
    md, _ := metadata.FromIncomingContext(ctx)
    mdCopy := md.Copy()
    mdCopy[header] = nil
    return metadata.NewIncomingContext(ctx, mdCopy)
}

type keyAppName struct{}

// GetAppName can be used to extract app name stored in a context.
func GetAppName(ctx context.Context) string {
    // Authenticate()?1???????????-???app name
    return ctx.Value(keyAppName{}).(string)
}

`tokenToAppName` ????????amap, ??????3????????????????o?o?????????
?????a?o????????3?????????????????a??????????1???????????????????????????|????3????????????????????????????????
??????a??|??o?????????

?????a???????? `Authenticate()`, ????1?3?????? http ?'??????????????????????????1?o?????o?????????
ctx ??-????????????????????????o?????????

`GetAppName()`????? ctx ??-?????o?????????

????????1?3???????|???????

func (s MailServer) Get(ctx context.Context, r *pb.GetRequest) (*pb.GetResponse, error) {
    app := auth.GetAppName(ctx)
    body, err := db.NewGetter(app).GetMailBody(r.MailIndex)
    return &pb.GetResponse{
        Result: getResult(err),
        Body:   body,
    }, nil
}

????????o?????????????????1????o??????????????o?????????????????

????????


golang


    // Create the client TLS credentials
    creds, err := credentials.NewClientTLSFromFile("key/server.crt", "mydomain.ztgame.com")
    if err != nil {
        panic(fmt.Errorf("could not load tls cert: %s", err))
    }

    // We don't need to error here, as this creates a pool and connections
    // will happen later
    conn, _ := grpc.Dial(
        serviceURL,
        grpc.WithTransportCredentials(creds),
        grpc.WithPerRPCCredentials(auth.TokenAuth{
            Token: "test",
        }))

    cli := pb.NewMailClient(conn)

??????????a??|? server.crt, ?????-?????????????????????????
NewClientTLSFromFile() ??????2??a??????????a???????????? server.crt ??-????????????
???????????????????2?????-??????????????????????????????????a???????????????o?a??? server.crt ??-????????????
????o?????????????????o????????|?????a?????????????????'???????? DNS ????a??????

Dial() ??????????a WithPerRPCCredentials ???o??????a??????

auth.TokenAuth ??|?????? PerRPCCredentials ?????????

package auth

import (
    "context"
)

type TokenAuth struct {
    Token string
}

func (t TokenAuth) GetRequestMetadata(ctx context.Context, in ...string) (map[string]string, error) {
    return map[string]string{
        "authorization-token": t.Token,
    }, nil
}

func (TokenAuth) RequireTransportSecurity() bool {
    return true
}

"authorization-token" ???????????????????????o|?????????http????'?-???|??2???

C++


C++ ???????????????????????golang??????????????????o grpc C++ ?o??2???? grpc-go ?????????

??????????? grpc ?o??? greeter_async_client2.cc:

int main(int argc, char** argv) {
    grpc::SslCredentialsOptions ssl_options;
    ssl_options.pem_root_certs = SERVER_CRT;
    // Create a default SSL ChannelCredentials object.
    auto channel_creds = grpc::SslCredentials(ssl_options);
    grpc::ChannelArguments cargs;
    cargs.SetSslTargetNameOverride("gamemail.ztgame.com");  // ?|????????o? DNS ??????????a?o?

    auto call_creds = grpc::MetadataCredentialsFromPlugin(
        std::unique_ptr<grpc::MetadataCredentialsPlugin>(new TokenAuthenticator(TOKEN)));

    auto compsited_creds = grpc::CompositeChannelCredentials(channel_creds, call_creds);

    // Create a channel using the credentials created in the previous step.
    auto channel = grpc::CreateCustomChannel("1.2.3.4:8000", compsited_creds, cargs);

    // Instantiate the client.
    MailClient tester(channel);
    ...

    return 0;
}

?????o C++ ?2???????????????????????? server.crt ?????????????????????-??'??????o??????a??????-???|??2???

    ssl_options.pem_root_certs = SERVER_CRT;

SERVER_CRT ????1??|???????

// server.crt ????????1
const char SERVER_CRT[] = R"(
-----BEGIN CERTIFICATE-----
TjERMA8GA1UECAwIU2hhbmdoYWkxEjAQBgNVBAcMCVNvbmdqaWFuZzEPMA0GA1UE
...
E6v50RCQgtWGmna+oy1I2UTVABdjBFnyKPEuz106mBfOhT6cg80hBHVgrV7sLHq8
76QolJm8yzZPL1qpiO4dKHHsCP6R
-----END CERTIFICATE-----
)";

TokenAuthenticator ????1??|????????????a?a????1?????????????

// TokenAuthenticator ???????????????????
// http://grpc.io/docs/guides/auth.html
class TokenAuthenticator : public grpc::MetadataCredentialsPlugin {
public:
  TokenAuthenticator(const std::string& token) : token_(token) {}

  grpc::Status GetMetadata(
      grpc::string_ref service_url, grpc::string_ref method_name,
      const grpc::AuthContext& channel_auth_context,
      std::multimap<grpc::string, grpc::string>* metadata) override {
    metadata->insert(std::make_pair("authorization-token", token_));
    return grpc::Status::OK;
  }

private:
  std::string token_;
};


???o? 2018-11-26 10:39 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/11/21/216073.html???o????o?Wed, 21 Nov 2018 02:57:00 GMThttp://www.598club.com/jinq0123/archive/2018/11/21/216073.htmlhttp://www.598club.com/jinq0123/comments/216073.htmlhttp://www.598club.com/jinq0123/archive/2018/11/21/216073.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/216073.htmlhttp://www.598club.com/jinq0123/services/trackbacks/216073.htmlvs2017 linux ?????????o??1??? vs ??????
(???o?????????? 2018.11)
 1 #!/usr/bin/python 
 2 # -*- coding: utf-8 -*-  
 3 
 4 '''
 5 gcc2vs.py
 6 
 7 ????????
 8 ????a????????-gcc????????????o???????????vs????????????o?vs3?????????????
 9 vs2017 linux ?????????o??o gcc ?????????????3???1???3??????|????
10 /var/tmp/src/dbe/Linux-Debug/Src/Team.cpp:16:1: ???????‘x’???????????a????????
11 ??????ovs??????, ?|?
12 /var/tmp/src/dbe/Linux-Debug/Src/Team.cpp(16):1: ???????‘x’???????????a????????
13 
14 ?|????????????
15 
16 |??????????? python, ?1?????? pyperclip
17 pip install pyperclip
18 
19 ????????????????o d:/tools/gcc2vs.py,
20 vs???????????????????->???????->?????
21   ????????gcc2vs(&V)
22   ????????python.exe
23   ????????d:/tools/gcc2vs.py
24   ????-"?????????o?a????"
25 
26 ????????VS2010???????????????????????????  
27 http://www.cnblogs.com/ChinaHook/p/4698733.html
28 
29 ???Linux?????o????o????????1???????o?a???????ctrl-A ???????????ctrl-C ?????????o????a?????????
30 ?????? alt-T,V ??????????????????? gcc2vs(&V), ??'??1????o????????????????????????1???????3???o????
31 '''
32 
33 import re
34 import pyperclip
35 
36 # ??????????????????
37 pattern = re.compile(r'/var/tmp/src/..-.-.-.-/Linux-Debug/(.*):([0-9]*):([0-9]*): ')
38 
39 test_lines_src = '''
40 /var/tmp/src/db71a8ec-90bb-2838-98df-2dd35e71166e/Linux-Debug/003_servers/103_LobbyServer/Src/Team.cpp:16:1: ???????‘x’???????????a????????
41 ???????'????
42 '''
43 test_lines_dst = '''
44 003_servers/103_LobbyServer/Src/Team.cpp(16):1: ???????‘x’???????????a????????
45 ???????'????
46 '''
47 assert test_lines_dst == re.sub(pattern, r'\1(\2):\3: ', test_lines_src)
48 
49 # ??a????????-???gcc??????????o
50 src = pyperclip.paste()
51 # ?????vs??????
52 dst = re.sub(pattern, r'\1(\2):\3: ', src)
53 print(dst)
54 


???o? 2018-11-21 10:57 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/11/12/216052.html???o????o?Mon, 12 Nov 2018 02:19:00 GMThttp://www.598club.com/jinq0123/archive/2018/11/12/216052.htmlhttp://www.598club.com/jinq0123/comments/216052.htmlhttp://www.598club.com/jinq0123/archive/2018/11/12/216052.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/216052.htmlhttp://www.598club.com/jinq0123/services/trackbacks/216052.html???3vs2017????3??????????

(???o?????????? 2018.11)

???????????????o? vs_community__1600125377.1541561546.exe?????????????????????????3???o???o????????????????

?????? Temp ??????????????????????2????????????????

????'????????????????????????????????????

* VS : How to fix stuck Visual Studio Community installation problem
    http://www.howtosolutions.net/2015/08/solving-installation-is-stuck-problem-in-visual-studio-community-edition/
* Resolving Installation Issues with Visual Studio 2017
    http://rion.io/2017/02/17/resolving-installation-issues-with-visual-studio-2017/
* Unable to start vs_installer.exe to install VS2017 Community
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/fc8f5a04-8687-48dd-987e-1cfac67566a1/unable-to-start-vsinstallerexe-to-install-vs2017-community?forum=vssetup
* VS 2017 Installer quits before starting
    http://developercommunity.visualstudio.com/content/problem/8993/vs-2017-installer-quits-before-starting.html
* VS2017????3??????????????????????????3??1?3? - ?????????????????1??????? - CSDN??????
    http://blog.csdn.net/qq951127336/article/details/71036868
* VS2017?????????a??????o_yanggy_????a??????
    http://blog.sina.com.cn/s/blog_702b606a0102y6n3.html

?????????2?????????

???????????1?????-?o???????`C:\Program Files (x86)\Microsoft Visual Studio\Installer`??????-?????????????????????????3?????????
?????????????1???????????????????????????????????????

??????????o??????-??? vs_installer.exe?????1??o??????'????????1????????????????????????????
??????1???????vs_installer.exe ???o???o??????????????o????

????????????? vs_community__1600125377.1541561546.exe????????????o???o??????????????o????

????????????????a Installer ??????????1?????????????????o????????????????????????????????????????????????????????????????????????????

?????-???????? vs2017.


???o? 2018-11-12 10:19 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/10/29/216026.html???o????o?Mon, 29 Oct 2018 10:47:00 GMThttp://www.598club.com/jinq0123/archive/2018/10/29/216026.htmlhttp://www.598club.com/jinq0123/comments/216026.htmlhttp://www.598club.com/jinq0123/archive/2018/10/29/216026.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/216026.htmlhttp://www.598club.com/jinq0123/services/trackbacks/216026.htmlgotest ??????????-????

(???o?????????? 2018.10)

?? gotest ?????????a??????????? mongodb ??-???????????????????????????????????????????????

?????o???????????? mgo ?????o??????'1?o??????????'???
???????????????????o gotest ??????????-???????????o???????????????????????????????????1??2??????????????????????

??????????????????o???????????1????????????????????????????

???????1???????????'?????????????? mgo ???????o????????????????????????2???????????????????o??????????????
??a?????????????????

ok      mail-server/server      0.519s
ok      mail-server/server      (cached)

??????????o?o????2??????????-??????????????o???????????????????o? cached ????a????o???

??o?o??|??-?????-????????????? -count=1 ????????
go test -count=1



???o? 2018-10-29 18:47 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/09/28/215964.html???o????o?Fri, 28 Sep 2018 06:01:00 GMThttp://www.598club.com/jinq0123/archive/2018/09/28/215964.htmlhttp://www.598club.com/jinq0123/comments/215964.htmlhttp://www.598club.com/jinq0123/archive/2018/09/28/215964.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215964.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215964.html

open-match???redis?????


(???o?????????? 2018.9)

open-match ???Google???????o?????????1??????????????

http://github.com/GoogleCloudPlatform/open-match

??1????-????????????????????????????-??? redis ??-?????????
`open-match\internal\statestorage\redis\playerq\playerq.go`
???????o??redis????-????????????

redis??-?????????????????

playerID


??????ID????|????`bfd09c94d646493f834a4abe83a5a68c`, ???????o hash. ??????????-???????

playerID.properties


????-???????????????json??2????|????

{
    "char.paladin": 1538102377,
    "map.eastworld": 1538102377,
    "mmr.rating": 1740,
    "mode.ctf": 1538102377,
    "timestamp.enter": 1538102377
}


??????????????????1?????|?????o??'??.

indices


set ????????????-????????????????????????|????

127.0.0.1:6379> smembers indices
1) "timestamp.enter"
2) "map.eastworld"
3) "mmr.rating"
4) "mode.ctf"
5) "char.paladin"

???????2????????

?????????????


?|? `timestamp.enter`, ???????o zset.
?????a?????????????????o????o??????a????o?????????????????????????????o????????????o playerID???

????|????

127.0.0.1:6379> zrange mmr.rating 1 3 WITHSCORES
1) "ef3736ef2f7941f1a159f279703d5f58"
2) "746"
3) "17ca3bf3a2134c2c90cbe48ebc29f9cb"
4) "891"
5) "b6450b311f3f413595e824897015c462"
6) "891"


???o? 2018-09-28 14:01 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/09/26/215949.html???o????o?Wed, 26 Sep 2018 09:37:00 GMThttp://www.598club.com/jinq0123/archive/2018/09/26/215949.htmlhttp://www.598club.com/jinq0123/comments/215949.htmlhttp://www.598club.com/jinq0123/archive/2018/09/26/215949.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215949.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215949.htmldocker build ???????????

(???o?????????? 2018.9)

Dockerfile.frontendapi ??-??? `RUN go get`, ??|???????????????

docker build . -f Dockerfile.frontendapi \
    -t registry.cn-shanghai.aliyuncs.com/jinq0123/openmatch-frontendapi:dev \
    --network host \
    --build-arg HTTP_PROXY=http://127.0.0.1:1080 \
    --build-arg HTTPS_PROXY=http://127.0.0.1:1080

?????o docker build ??????????a??1?????????????????????????? network ??o host, ????1?????????????????o????????????

????????
http://stackoverflow.com/questions/22179301/how-do-you-run-apt-get-in-a-dockerfile-behind-a-proxy

[root@pppdc9prda2y java]# docker build
  --build-arg https_proxy=$HTTP_PROXY --build-arg http_proxy=$HTTP_PROXY
  --build-arg HTTP_PROXY=$HTTP_PROXY --build-arg HTTPS_PROXY=$HTTP_PROXY
  --build-arg NO_PROXY=$NO_PROXY  --build-arg no_proxy=$NO_PROXY -t java .


???o? 2018-09-26 17:37 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/09/04/215903.html???o????o?Tue, 04 Sep 2018 07:17:00 GMThttp://www.598club.com/jinq0123/archive/2018/09/04/215903.htmlhttp://www.598club.com/jinq0123/comments/215903.htmlhttp://www.598club.com/jinq0123/archive/2018/09/04/215903.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215903.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215903.htmlK8s????NodePort

(???o?????????? 2018.9)

??????????NodePort??'?2????????????o?????????????2?a?????????????NodePort,
 ???????k8s?a????????????a?????????
 
$ cat get_node_port.yaml
kind: Service
apiVersion: v1
metadata:
  name: jq-service
spec:
  type: NodePort
  selector:
    app: MyApp
  ports:
  - protocol: TCP
    port: 80

$ kubectl apply -f get_node_port.yaml
service "jq-service" configured
$ kubectl describe svc/jq-service
Name:                     jq-service
Namespace:                default
Labels:                   <none>
Annotations:              kubectl...
Selector:                 app=MyApp
Type:                     NodePort
IP:                       10.104.228.187
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  32115/TCP
Endpoints:                <none>
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>


???????????k8s??????o?NodePort 32115???

????????|?????????a????????NodePort???????????????????????????????????

package main

import (
    "context"
    "fmt"
    "log"
    "io/ioutil"

    "github.com/ghodss/yaml"
    "github.com/ericchiang/k8s"
    corev1 "github.com/ericchiang/k8s/apis/core/v1"
)

func main() {
    data, err := ioutil.ReadFile("config")
    if err != nil {
        panic(err)
    }

    // Unmarshal YAML into a Kubernetes config object.
    var config k8s.Config
    if err := yaml.Unmarshal(data, &config); err != nil {
        panic(err)
    }

    client, err := k8s.NewClient(&config)
    // client, err := k8s.NewInClusterClient()
    if err != nil {
        log.Fatal(err)
    }

    var svc corev1.Service
    if err := client.Get(context.Background(), "default", "jq-service", &svc); err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%d\n", *svc.Spec.Ports[0].NodePort)
}

?????????|??????config: `cp ~/.kube/config .`


???o? 2018-09-04 15:17 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/08/30/215889.html???o????o?Thu, 30 Aug 2018 02:58:00 GMThttp://www.598club.com/jinq0123/archive/2018/08/30/215889.htmlhttp://www.598club.com/jinq0123/comments/215889.htmlhttp://www.598club.com/jinq0123/archive/2018/08/30/215889.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215889.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215889.html???????????git submodule

(???o?????????? 2018.8)

?-???????submodule????? .gitmodule ????????-???TortoiseGit ?????? Submodule Update ????????
????????????????? submodule, .gitmodule ????????-??????????????????3? update.
golang????????-???vendor????????????????????????????????????a??| .git ????????????????????o??????a??????submodule.
?? Repo-browser ???????a???????????asubmodule?????, clone ??o??????a????????a??o?????????

????????asubmodule??????? git delete, ????o??????????????

git.exe add -f [...]

fatal: pathspec 'src/vendor/github.com/grpc-ecosystem/grpc-opentracing' did not match any files

git did not exit cleanly (exit code 128)

git delete ??????????1?????3?????o???

??????????????'???????????????git delete???, ??????????o?1?Push. ????????a???????a????3????





???o? 2018-08-30 10:58 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/08/29/215886.html???o????o?Wed, 29 Aug 2018 02:59:00 GMThttp://www.598club.com/jinq0123/archive/2018/08/29/215886.htmlhttp://www.598club.com/jinq0123/comments/215886.htmlhttp://www.598club.com/jinq0123/archive/2018/08/29/215886.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215886.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215886.htmlgrpc??-???dns'????????

(???o?????????? 2018.8)

grpc-go ??-?|???????????????????????????????aIP?1??'???????

    conn, err := grpc.Dial(
        "dns:///rng-headless:8081",
        grpc.WithBalancerName(roundrobin.Name),
        grpc.WithInsecure())

???????????????????o????????????????`"dns://authority/endpoint_name"`,
?-?? authority ??o??o????|????http://github.com/grpc/grpc/blob/master/doc/naming.md

???????????3??a????????????????????3??a????????????????

[jinqing@host-10-2-3-4 RoundRobin]$ kubectl run -it --rm jinqing-roundrobin --image=jinq0123/roundrobin:4
If you don't see a command prompt, try pressing enter.
2018/08/28 10:18:01 request 7754383576636566559
2018/08/28 10:18:02 request 2543876599219675746
2018/08/28 10:18:03 request 927204261937181213
2018/08/28 10:18:04 request 7754383576636566559
2018/08/28 10:18:05 request 2543876599219675746
2018/08/28 10:18:06 request 927204261937181213
...

??????????????????a????o????????????????????????o???????????????????????
http://github.com/kcollasarundell/balancing-on-k8s ?????1??????

...
const (
        port = ":8081"
)

type server struct{}

var r int64

func init(){
    rand.Seed(time.Now().UnixNano())
    r = rand.Int63()
}

func (s *server) Rng(context.Context, *rng.Source) (*rng.RN, error) {
        return &rng.RN{RN: r}, nil
}

func main() {
        lis, err := net.Listen("tcp", port)
        if err != nil {
                log.Fatalf("failed to listen: %v", err)
        }
        s := grpc.NewServer()
        rng.RegisterRngServer(s, &server{})
        // Register reflection service on gRPC server.
        reflection.Register(s)

        if err := s.Serve(lis); err != nil {
                log.Fatalf("failed to serve: %v", err)
        }
}

???????????????????????????????????? `balancing-on-k8s\backend\kube.yaml` ???????
kubectl apply -f kube.yaml

`backend\kube.yaml` ?????o?o??????a ClusterIP ??????????????a Headless ????????????2?o? 3 ??a?????????????????
[jinqing@host-10-2-3-4 RoundRobin]$ kubectl get svc
NAME           TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)             AGE
kubernetes     ClusterIP   10.96.0.1       <none>        443/TCP             93d
rng-cluster    ClusterIP   10.111.30.205   <none>        8081/TCP            4h
rng-headless   ClusterIP   None            <none>        8081/TCP,8080/TCP   4h

????????????????a?????????grpc, ??????????????????????????????????o?????
`balancing-on-k8s\clientSideBalancer\RoundRobin\main.go`??-??????????|???????????????
??????grpc??????????? 443 ?????????'????

?????1?????????????|?3????????????????'???????????????1???????????3?????????
kubectl scale --replicas=5 deployment/rng

?|??????? ClusterIP ??????, ??????????????1?o??????aClusterIP;
?|??????? Headless ???????????????????????1?o??????aPod???IP:

/ # nslookup rng-headless
Server:         10.96.0.10
Address:        10.96.0.10#53

Name:   rng-headless.default.svc.cluster.local
Address: 10.244.3.27
Name:   rng-headless.default.svc.cluster.local
Address: 10.244.0.108
Name:   rng-headless.default.svc.cluster.local
Address: 10.244.2.66

/ # nslookup rng-cluster
Server:         10.96.0.10
Address:        10.96.0.10#53

Name:   rng-cluster.default.svc.cluster.local
Address: 10.111.30.205

/ #

?|???????? "dns:///", ???????????????????????????

conn, err := grpc.Dial(
        "rng-headless:8081",
        grpc.WithBalancerName(roundrobin.Name),
        ...

?????a??????????????a???????????a??????????????pod?????????????????????????|?????a?????????
??????????1??????????????????????2?????????????????????????????
??2??a?????????????????????????????????????????????????1??o1?????????????????????????????????

?|??????????????????????????????????????adns'??????????????????o?????????o?????????????????????a?????????????????

????????
Exploring Kubernetes Service Discovery and loadbalancing ( http://kca.id.au/post/k8s_service/ )


???o? 2018-08-29 10:59 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/08/12/215842.html???o????o?Sun, 12 Aug 2018 04:24:00 GMThttp://www.598club.com/jinq0123/archive/2018/08/12/215842.htmlhttp://www.598club.com/jinq0123/comments/215842.htmlhttp://www.598club.com/jinq0123/archive/2018/08/12/215842.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215842.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215842.html?????o???? Unity Grpc

(???o?????????? 2018.8)

* ????? Unit2018, ?????? .NET 4.x
* ?????o?????a?1???????????? .NET 4.x
    Edit->Project Settings->Player->Other Settings
      ->Configuration->Script Runtime Version->.Net 4.x Equivalent
* ??? http://packages.grpc.io/ ??? Daily Builds ?????????????
    grpc-protoc_windows_x86-VERSION.zip
    grpc_unity_package.VERSION.zip
* grpc_unity_package.VERSION.zip
    ?????? Assets ?????????
* ??? github grpc ????? examples/protos/helloworld.proto ??o Assets/protos/helloworld.proto
* ?????o Assets/Scripts/Greeter/, ?1??????????????????
    protoc.exe -I../../../protos --csharp_out=. ../../../protos/helloworld.proto --grpc_out=. --plugin=protoc-gen-grpc=grpc_csharp_plugin.exe
    + ??|??????? grpc-protoc_windows_x86-VERSION.zip ???? protoc.exe???grpc_csharp_plugin.exe
    + ?????? Helloworld.cs HelloworldGrpc.cs
* ??????????????
    + ?????oChannel?????????????
    channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
    + ?????o?????????1??????o???
    var client = new Greeter.GreeterClient(channel);
    HelloReply reply = client.SayHello(new HelloRequest { Name = "Jin Qing" });
* ?????'??????????http://gitee.com/jinq0123/unity-grpc-sample
* ????????????????????????o?????????


???o? 2018-08-12 12:24 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/07/22/215796.html???o????o?Sun, 22 Jul 2018 03:14:00 GMThttp://www.598club.com/jinq0123/archive/2018/07/22/215796.htmlhttp://www.598club.com/jinq0123/comments/215796.htmlhttp://www.598club.com/jinq0123/archive/2018/07/22/215796.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215796.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215796.htmlk8s??????go?????????o???

(???o?????????? 2018.7)

?????????????????|??????????docker?????????????????????????????? kubectl run ???????
??|????????????2????ao???|????????????????????????????????????1??????

?????????o?????? ericchiang/k8s, ????????1??? client-go |??????????????

????????????????????`k8s.NewInClusterClient()`?????o???
??????????????????? `NewClient(config *Config)`, ??|??????????????
???????????? ~/.kube/config ???????????
????? http://github.com/ericchiang/k8s/issues/79

???????|???????

package main

import (
    "context"
    "fmt"
    "log"
    "io/ioutil"

    "github.com/ghodss/yaml"
    "github.com/ericchiang/k8s"
    corev1 "github.com/ericchiang/k8s/apis/core/v1"
)

func main() {
    data, err := ioutil.ReadFile("config")
    if err != nil {
        panic(err)
    }

    // Unmarshal YAML into a Kubernetes config object.
    var config k8s.Config
    if err := yaml.Unmarshal(data, &config); err != nil {
        panic(err)
    }

    client, err := k8s.NewClient(&config)
    // client, err := k8s.NewInClusterClient()
    if err != nil {
        log.Fatal(err)
    }

    var nodes corev1.NodeList
    if err := client.List(context.Background(), "", &nodes); err != nil {
        log.Fatal(err)
    }
    for _, node := range nodes.Items {
        fmt.Printf("name=%q schedulable=%t\n", *node.Metadata.Name, !*node.Spec.Unschedulable)
    }
}

yaml ?o????o? ghodss/yaml?????????? go-yaml, ???????????
`yaml: unmarshal errors`
????http://github.com/ericchiang/k8s/issues/81

????? .kube/config ????????????????????????o??????????1???

[jinqing@host-10-1-2-19 out-cluster]$ cp ~/.kube/config .
[jinqing@host-10-1-2-19 out-cluster]$ ./out-cluster
name="host-10-1-2-20" schedulable=true
name="host-10-1-2-21" schedulable=true
name="host-10-1-2-22" schedulable=true
name="host-10-1-2-19" schedulable=true
name="host-10-1-2-18" schedulable=true


???o? 2018-07-22 11:14 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/07/14/215783.html???o????o?Sat, 14 Jul 2018 03:43:00 GMThttp://www.598club.com/jinq0123/archive/2018/07/14/215783.htmlhttp://www.598club.com/jinq0123/comments/215783.htmlhttp://www.598club.com/jinq0123/archive/2018/07/14/215783.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215783.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215783.htmlkubernetes?????o???????????????

(???o?????????? 2018.7)

????????????????-???????'??????????????????????????????????????? kubernetes statefulset ??????????a?????????

??o?o?????????????????'??????'?????????????o? statefulset |?????? headless ?????????
??????o?????a???????????o NodePort ??????????????, ?1?????????Pod????|??-?????????

????? bootcamp.yml ????????o?o? bootcamp headless ??????(clusterIP: None),
????????o?o? bootcamp StatefulSet, ????????a????o 2.
???????????o bootcamp-0,1,2 ?????????????????1?o? bootcamp-0,1,2 pod.

????????a????o?????????a??????????3???????????????2??????1?o??????????????????????

????????-?????1??????????????????????a????'???????????????????? bootcamp-0,1,2 pod ?????????1???????? IP,
???????1?o??????????????????????????????????????????????????'?????

[jinqing@host-10-240-79-10 statefulset]$ cat bootcamp.yml
apiVersion: v1
kind: Service
metadata:
  name: bootcamp
  namespace: jq
  labels:
    name: bootcamp
spec:
  ports:
    - port: 8080
  clusterIP: None  # StatefulSet|???Headless??????
  selector:
    app: bootcamp  # ????? bootcamp ?o???

---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: bootcamp
  namespace: jq
spec:
  serviceName: bootcamp  # ???????? Headless ?????????
  replicas: 2
  template:
    metadata:
      labels:
        app: bootcamp  # ?o????????????????????-??? selector ??1?o?
    spec:
      containers:
      - name: bootcamp
        image: docker.io/jocatalin/kubernetes-bootcamp:v1

---
kind: Service
apiVersion: v1
metadata:
  name: bootcamp-0
  namespace: jq
spec:
  type: NodePort  # ??1????????
  externalTrafficPolicy: Local  # ???|??????????????????1
  selector:
    app: bootcamp
    statefulset.kubernetes.io/pod-name: bootcamp-0  # ????? pod
  ports:
  - protocol: TCP
    nodePort: 30880  # ??1????????
    port: 8080
---
kind: Service
apiVersion: v1
metadata:
  name: bootcamp-1
  namespace: jq
spec:
  type: NodePort
  externalTrafficPolicy: Local
  selector:
    app: bootcamp
    statefulset.kubernetes.io/pod-name: bootcamp-1
  ports:
  - protocol: TCP
    nodePort: 30881
    port: 8080
---
kind: Service
apiVersion: v1
metadata:
  name: bootcamp-2
  namespace: jq
spec:
  type: NodePort
  externalTrafficPolicy: Local
  selector:
    app: bootcamp
    statefulset.kubernetes.io/pod-name: bootcamp-2
  ports:
  - protocol: TCP
    nodePort: 30882
    port: 8080

?????o statefulset ????????a??????????????????????-??????????????????o????????????????a?????????

????? externalTrafficPolicy: Local ?????????|??-?????????
????? service.spec.externalTrafficPolicy ????'??????

http://kubernetes.io/docs/tutorials/services/source-ip/#source-ip-for-services-with-type-nodeport

Setting service.spec.externalTrafficPolicy to the value Local will only proxy requests to local endpoints, never forwarding traffic to other nodes and thereby preserving the original source IP address. If there are no local endpoints, packets sent to the node are dropped, ...

?????o????????????aPod???????????????1??????????????1??????????????o?????????? 30880-30882???
?|??????????????a????1??a????????a??????????????1???????????????????????????a???

?????o?????????

[jinqing@host-10-240-79-10 statefulset]$ kubectl apply -f bootcamp.yml
service "bootcamp" created
statefulset.apps "bootcamp" created
service "bootcamp-0" created
service "bootcamp-1" created
service "bootcamp-2" created

???????|???????

[jinqing@host-10-240-79-10 statefulset]$ kubectl get service -n jq
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
bootcamp     ClusterIP   None             <none>        8080/TCP         3m
bootcamp-0   NodePort    10.96.128.137    <none>        8080:30880/TCP   3m
bootcamp-1   NodePort    10.109.2.56      <none>        8080:30881/TCP   3m
bootcamp-2   NodePort    10.102.181.193   <none>        8080:30882/TCP   3m

2??a?????????

[jinqing@host-10-240-79-10 statefulset]$ kubectl get pod -n jq -o wide
NAME         READY     STATUS    RESTARTS   AGE       IP            NODE
bootcamp-0   1/1       Running   0          4m        10.244.0.42   host-10-240-79-10
bootcamp-1   1/1       Running   0          4m        10.244.1.63   host-10-240-79-11

?????????????????????????1??????????a??????????

[jinqing@host-10-240-79-10 statefulset]$ curl 10.240.79.10:30880
Hello Kubernetes bootcamp! | Running on: bootcamp-0 | v=1
[jinqing@host-10-240-79-10 statefulset]$ curl 10.240.79.10:30881
curl: (7) Failed connect to 10.240.79.10:30881; Connection timed out
[jinqing@host-10-240-79-10 statefulset]$ curl 10.240.79.11:30880
curl: (7) Failed connect to 10.240.79.11:30880; Connection timed out
[jinqing@host-10-240-79-10 statefulset]$ curl 10.240.79.11:30881
Hello Kubernetes bootcamp! | Running on: bootcamp-1 | v=1

?2????'???????????30881???????????????? bootcamp-1???

[jinqing@host-10-240-79-10 statefulset]$ curl 10.240.79.11:30881
Hello Kubernetes bootcamp! | Running on: bootcamp-1 | v=1
[jinqing@host-10-240-79-10 statefulset]$ curl 10.240.79.11:30881
Hello Kubernetes bootcamp! | Running on: bootcamp-1 | v=1
[jinqing@host-10-240-79-10 statefulset]$ curl 10.240.79.11:30881
Hello Kubernetes bootcamp! | Running on: bootcamp-1 | v=1
[jinqing@host-10-240-79-10 statefulset]$ curl 10.240.79.11:30881
Hello Kubernetes bootcamp! | Running on: bootcamp-1 | v=1
[jinqing@host-10-240-79-10 statefulset]$ curl 10.240.79.11:30881
Hello Kubernetes bootcamp! | Running on: bootcamp-1 | v=1

?1???????????????????.

30882 ??????????3?????????

[jinqing@host-10-240-79-10 statefulset]$ curl 10.240.79.11:30882
curl: (7) Failed connect to 10.240.79.11:30882; Connection refused
[jinqing@host-10-240-79-10 statefulset]$ curl 10.240.79.10:30882
curl: (7) Failed connect to 10.240.79.10:30882; Connection refused

3??a????????????????????

[root@host-10-240-79-11 tmp]# netstat -ntl | grep 3088
tcp6       0      0 :::30881                :::*                    LISTEN     
tcp6       0      0 :::30882                :::*                    LISTEN     
tcp6       0      0 :::30880                :::*                    LISTEN     

iptables-save ????o?|????, ?????- 10.244???Pod????????????

?2?????????????????????1?????????????????????

-A KUBE-NODEPORTS -s 127.0.0.0/8 -p tcp -m comment --comment "jq/bootcamp-1:" -m tcp --dport 30881 -j KUBE-MARK-MASQ
-A KUBE-NODEPORTS -p tcp -m comment --comment "jq/bootcamp-1:" -m tcp --dport 30881 -j KUBE-XLB-LJXDQ4W47M42IZBH
-A KUBE-NODEPORTS -s 127.0.0.0/8 -p tcp -m comment --comment "jq/bootcamp-0:" -m tcp --dport 30880 -j KUBE-MARK-MASQ
-A KUBE-NODEPORTS -p tcp -m comment --comment "jq/bootcamp-0:" -m tcp --dport 30880 -j KUBE-XLB-U5NEOQT6R5WSBVOH

-A KUBE-XLB-LJXDQ4W47M42IZBH -s 10.244.0.0/16 -m comment --comment "Redirect pods trying to reach external loadbalancer VIP to clusterIP" -j KUBE-SVC-LJXDQ4W47M42IZBH
-A KUBE-XLB-LJXDQ4W47M42IZBH -m comment --comment "jq/bootcamp-1: has no local endpoints" -j KUBE-MARK-DROP
-A KUBE-XLB-U5NEOQT6R5WSBVOH -s 10.244.0.0/16 -m comment --comment "Redirect pods trying to reach external loadbalancer VIP to clusterIP" -j KUBE-SVC-U5NEOQT6R5WSBVOH
-A KUBE-XLB-U5NEOQT6R5WSBVOH -m comment --comment "jq/bootcamp-0: has no local endpoints" -j KUBE-MARK-DROP

????????????????????1?????????????? Pod 8080???

-A KUBE-NODEPORTS -s 127.0.0.0/8 -p tcp -m comment --comment "jq/bootcamp-0:" -m tcp --dport 30880 -j KUBE-MARK-MASQ
-A KUBE-NODEPORTS -p tcp -m comment --comment "jq/bootcamp-0:" -m tcp --dport 30880 -j KUBE-XLB-U5NEOQT6R5WSBVOH
-A KUBE-NODEPORTS -s 127.0.0.0/8 -p tcp -m comment --comment "jq/bootcamp-1:" -m tcp --dport 30881 -j KUBE-MARK-MASQ
-A KUBE-NODEPORTS -p tcp -m comment --comment "jq/bootcamp-1:" -m tcp --dport 30881 -j KUBE-XLB-LJXDQ4W47M42IZBH

-A KUBE-XLB-LJXDQ4W47M42IZBH -s 10.244.0.0/16 -m comment --comment "Redirect pods trying to reach external loadbalancer VIP to clusterIP" -j KUBE-SVC-LJXDQ4W47M42IZBH
-A KUBE-XLB-LJXDQ4W47M42IZBH -m comment --comment "Balancing rule 0 for jq/bootcamp-1:" -j KUBE-SEP-LJQA4WUIKJUQ5ALU
-A KUBE-XLB-U5NEOQT6R5WSBVOH -s 10.244.0.0/16 -m comment --comment "Redirect pods trying to reach external loadbalancer VIP to clusterIP" -j KUBE-SVC-U5NEOQT6R5WSBVOH
-A KUBE-XLB-U5NEOQT6R5WSBVOH -m comment --comment "jq/bootcamp-0: has no local endpoints" -j KUBE-MARK-DROP

-A KUBE-SEP-LJQA4WUIKJUQ5ALU -s 10.244.1.63/32 -m comment --comment "jq/bootcamp-1:" -j KUBE-MARK-MASQ
-A KUBE-SEP-LJQA4WUIKJUQ5ALU -p tcp -m comment --comment "jq/bootcamp-1:" -m tcp -j DNAT --to-destination 10.244.1.63:8080

30882 ??????????3??????
-A KUBE-EXTERNAL-SERVICES -p tcp -m comment --comment "jq/bootcamp-2: has no endpoints" -m addrtype --dst-type LOCAL -m tcp --dport 30882 -j REJECT --reject-with icmp-port-unreachable

?????????????1???

[jinqing@host-10-240-79-10 statefulset]$ kubectl get statefulset -n jq
NAME       DESIRED   CURRENT   AGE
bootcamp   2         2         45m
[jinqing@host-10-240-79-10 statefulset]$ kubectl scale --replicas=3 statefulset/bootcamp -n jq
statefulset.apps "bootcamp" scaled
[jinqing@host-10-240-79-10 statefulset]$ kubectl get statefulset -n jq
NAME       DESIRED   CURRENT   AGE
bootcamp   3         3         47m
[jinqing@host-10-240-79-10 statefulset]$ kubectl get pod -n jq -o wide
NAME         READY     STATUS    RESTARTS   AGE       IP            NODE
bootcamp-0   1/1       Running   0          48m       10.244.0.42   host-10-240-79-10
bootcamp-1   1/1       Running   0          48m       10.244.1.63   host-10-240-79-11
bootcamp-2   1/1       Running   0          45s       10.244.2.60   host-10-240-79-12
[jinqing@host-10-240-79-10 statefulset]$ curl 10.240.79.12:30882
Hello Kubernetes bootcamp! | Running on: bootcamp-2 | v=1


???o? 2018-07-14 11:43 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/06/25/215743.html???o????o?Mon, 25 Jun 2018 09:16:00 GMThttp://www.598club.com/jinq0123/archive/2018/06/25/215743.htmlhttp://www.598club.com/jinq0123/comments/215743.htmlhttp://www.598club.com/jinq0123/archive/2018/06/25/215743.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215743.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215743.html????????????????ogo??????????3?3?

(???o?????????? 2018.6)

????a???
http://www.ardanlabs.com/blog/2017/02/package-oriented-design.html

If a package wants to import another package at the same level:

* Question the current design choices of these packages.
* If reasonable, move the package inside the source tree for the package that wants to import it.
* Use the source tree to show the dependency relationships.


???o? 2018-06-25 17:16 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/06/25/215742.html???o????o?Mon, 25 Jun 2018 08:51:00 GMThttp://www.598club.com/jinq0123/archive/2018/06/25/215742.htmlhttp://www.598club.com/jinq0123/comments/215742.htmlhttp://www.598club.com/jinq0123/archive/2018/06/25/215742.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215742.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215742.htmlGolang?????????

(???o?????????? 2018.6)

????a???

http://talks.golang.org/2014/organizeio.slide#1

The name of a package

Keep package names short and meaningful.
Don't use underscores, they make package names long.

    io/ioutil not io/util
    suffixarray not suffix_array

Don't overgeneralize. A util package could be anything.

The name of a package is part of its type and function names.
On its own, type Buffer is ambiguous. But users see:

    buf := new(bytes.Buffer)

Choose package names carefully.

Choose good names for users.


???o? 2018-06-25 16:51 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/06/13/215722.html???o????o?Wed, 13 Jun 2018 06:27:00 GMThttp://www.598club.com/jinq0123/archive/2018/06/13/215722.htmlhttp://www.598club.com/jinq0123/comments/215722.htmlhttp://www.598club.com/jinq0123/archive/2018/06/13/215722.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215722.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215722.htmletcd+registrator+confd ???????????

(???o?????????? 2018.6)

?????ok8s????? etcd, ???????? etcd ?????o?????????????? DB.

registrator ????????o docker ??1?????????????????a???3????? etcd.

confd ????? etcd, ????????????????????

????????????aetcd???o?????????

docker run -d \
  -p 12379:2379 \
  --name jinqing-etcd \
  quay.io/coreos/etcd \
   /usr/local/bin/etcd \
  --listen-client-urls http://0.0.0.0:2379 \
  --advertise-client-urls http://0.0.0.0:12379

??????? registrator:

docker run -d --rm \
    --name=jinqing-registrator \
    --net=host \
    --volume=/var/run/docker.sock:/tmp/docker.sock \
    gliderlabs/registrator:latest \
      -ip="192.168.93.183" \
      etcd://127.0.0.1:12379/registrator

????????a????????????o??? etcd. ???????|???-ip????????????????oIP????3????? registrator ?????????

?? etcdkeeper ?????????????a???3???????????????registrator ????????? etcd v3.

??????????? confd

mkdir -p /etc/confd/{conf.d,templates}

/etc/confd/conf.d/myconfig.toml

[template]
src = "services.toml.tmpl"
dest = "/tmp/services.toml"
keys = [
    "/registrator",
]

/etc/confd/templates/services.toml.tmpl

[config]
{{- range lsdir "/registrator"}}
{{-     $serviceName := . }}
{{-     $serviceDir := printf "/registrator/%s/*" $serviceName }}

    [config.{{ $serviceName }}]
    # {{ $serviceDir }}

{{-     range gets $serviceDir }}
    {{ base .Key }} = {{ .Value }}
{{-     end }}

{{- end}}

# End of [config].

?? lsdir ?????o????????????????????????????? gets ????????????????????????????1???

???? confd:

~/go/bin/confd -onetime -backend etcd -node http://127.0.0.1:12379

[jinqing@localhost confd]$ cat /tmp/services.toml
[config]

    [config.etcd-2379]
    # /registrator/etcd-2379/*
    localhost.tech:jinqing-etcd:2379 = 192.168.93.183:12379

    [config.nginx]
    # /registrator/nginx/*
    localhost.tech:jinqing-nginx:80 = 192.168.93.183:1024

    [config.registry]
    # /registrator/registry/*
    localhost.tech:registry:5000 = 192.168.93.183:5000

# End of [config].


???o? 2018-06-13 14:27 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/06/12/215720.html???o????o?Tue, 12 Jun 2018 03:15:00 GMThttp://www.598club.com/jinq0123/archive/2018/06/12/215720.htmlhttp://www.598club.com/jinq0123/comments/215720.htmlhttp://www.598club.com/jinq0123/archive/2018/06/12/215720.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215720.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215720.htmlgrpc-go???actor?????

(???o?????????? 2018.6)

grpc-go????????????????a????????????a????????????????-???????
????????????????-???????????????????????????'?????1?3??????????'????????a?????????????????
????????????'???????oactor???grpc???????Call()???Post()??1?3???????????
?????-Call()????-??????????????Post()???????-???????????????????

type Room struct {
    // actC ?????????????????Room??????????????????Channel??????????-????????????????????
    // Action ?????, ??????????????????????????????.
    actC chan func()

    ...
}

// Run ????????'?????.
func (r *Room) Run() {
    ticker := time.NewTicker(20 * time.Millisecond)
    defer ticker.Stop()

    for r.running {
        select {
        case act := <-r.actC:
            act()
        case <-ticker.C:
            r.tick()
        }
    }
}

// Call calls a function f and returns the result.
// f runs in the Room's goroutine.
func (r *Room) Call(f func() interface{}) interface{} {
    // ?????????ch?????
    ch := make(chan interface{}, 1)
    r.actC <- func() {
        ch <- f()
    }
    // ?-??????'?????????????
    return <-ch
}

// Post ???????a???????????????????????-????.
func (r *Room) Post(f func()) {
    r.actC <- f
}

grpc????????1?3??|????

func (m *RoomService) Test(ctx context.Context, req *pb.TestReq) (*pb.TestResp, error) {
    conn := conn_mgr.GetConn(ctx)
    if conn == nil {
        return nil, fmt.Errorf("can not find connection")
    }

    room := conn.GetRoom()
    resp := room.Call(func() interface{} {
        return room.Test(req)
    })

    return resp.(*pb.TestResp), nil
}

???o? 2018-06-12 11:15 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/05/27/215683.html???o????o?Sun, 27 May 2018 11:22:00 GMThttp://www.598club.com/jinq0123/archive/2018/05/27/215683.htmlhttp://www.598club.com/jinq0123/comments/215683.htmlhttp://www.598club.com/jinq0123/archive/2018/05/27/215683.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215683.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215683.html?? kubeadm --config ?????o k8s ????

(???o?????????? 2018.5)

??????????o????yum????????docker???????????????????????????'?????????????o k8s ???????

K8s ????????o v1.10.3

????????

http://blog.csdn.net/u010209217/article/details/78533936
Kubernetes 1.7.5???2??????kubernates-dashboard 1.7?????

http://www.cnblogs.com/liangDream/p/7358847.html
CentOS7.3?????kubeadm?????kubernetes1.7.3?????'???(?????1???????????????)

http://yq.aliyun.com/articles/66474
?????o?????????2Kubernetes - VPC??????

Docker ?2????????

?????????o????yum?o???????????'????????:
yum -y install kubectl kubeadm kubelet

vi /etc/systemd/system/kubelet.service.d/10-kubeadm.conf, ??okubelet??????????a????????????,
????kubelet??????????????pod????????????????????k8s????o???????pause-amd64:3.0??????o?
--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0

export KUBE_REPO_PREFIX ?????1?????????kube??????o??2??1.8????????????????????|???1??o?????????????-????? imageRepository???

kubeadm.yaml ?o??????
http://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init/

apiVersion: kubeadm.k8s.io/v1alpha1
kind: MasterConfiguration
api:
  advertiseAddress: "10.20.79.10"
networking:
  podSubnet: "10.244.0.0/16"
kubernetesVersion: "v1.10.3"
imageRepository: "registry.cn-hangzhou.aliyuncs.com/google_containers"

???????????????o???
kubeadm init --config kubeadm.yaml

???????3?????1???

??|??????? kubelet.service, ??????????????????-|??????
systemctl enable kubelet && systemctl start kubelet
??|???3?- swap:
[ERROR Swap]: running with swap on is not supported. Please disable swap
swapoff -a

???????????? ls -ltr /etc/kubernetes/manifests/
yaml??????????????????a???????????????????????????????????????

[ERROR FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml]: /etc/kubernetes/manifests/kube-apiserver.yaml already exists
[ERROR Port-10250]: Port 10250 is in use
kubeadm????a?????????????????????????|?????????????????????“??????”????|???????,???????????????????????init???????????????????”kubeadm reset”???????????????,?????????????

journalctl -xeu kubelet
???????????kubelet???????????1????????

failed to run Kubelet: failed to create kubelet: misconfiguration: kubelet cgroup driver: "systemd" is different from docker cgroup driver: "cgroupfs"
??|??????1 /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
sed -i "s/cgroup-driver=systemd/cgroup-driver=cgroupfs/g" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
systemctl daemon-reload && systemctl restart kubelet


???o? 2018-05-27 19:22 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/05/14/215637.html???o????o?Mon, 14 May 2018 02:42:00 GMThttp://www.598club.com/jinq0123/archive/2018/05/14/215637.htmlhttp://www.598club.com/jinq0123/comments/215637.htmlhttp://www.598club.com/jinq0123/archive/2018/05/14/215637.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215637.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215637.html????Golang???assert?o?

(???o?????????? 2018.5)

http://github.com/aurelien-rainone/assertgo

Conditionally compiled assertions in Go

???C++??-???assert()????????????a?????|??????????????????????????? debug ?????????????

?|????

$ go run -tags debug main.go

??????o??????

assert.True(true, "never printed")



???o? 2018-05-14 10:42 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/05/09/215627.html???o????o?Wed, 09 May 2018 10:32:00 GMThttp://www.598club.com/jinq0123/archive/2018/05/09/215627.htmlhttp://www.598club.com/jinq0123/comments/215627.htmlhttp://www.598club.com/jinq0123/archive/2018/05/09/215627.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215627.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215627.htmlconsul???????-????????a?????

(???o?????????? 2018.5)

consul?????????-??????????????a?????????????

* -bind
    ?????????????????o???????????????o??? 0.0.0.0
* -clint
    ?????????????????o? RPC, DNS, HTTP and HTTPS?????o??? 127.0.0.1
* -serf-lan-bind
    ?????????????????o?????????????????????o???????? -bind ?????
* -serf-wan-bind
    ?????????????????o?跨??o?????????????o???????? -bind ?????
* -advertise
    ???????????????????????????-??????????1?????o???????? -bind ?????
* -advertise-wan
    ?????????????????????????????o????????????????1?????o???????? -advertise ?????
* -join -retry-join
    ????????????????????????
* -join-wan -retry-join-wan
    跨??o????|????????????????
* -recursor
    ??????DNS?????

?????1????????? http://www.consul.io/docs/agent/options.html#command-line-options


???o? 2018-05-09 18:32 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/05/04/215617.html???o????o?Fri, 04 May 2018 08:07:00 GMThttp://www.598club.com/jinq0123/archive/2018/05/04/215617.htmlhttp://www.598club.com/jinq0123/comments/215617.htmlhttp://www.598club.com/jinq0123/archive/2018/05/04/215617.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215617.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215617.html

????????????????????

江苏快三开奖结果(???o?????????? 2018.5)

江苏快三开奖结果?????????????????????????????

  • 江苏快三开奖结果Service Registry ???????3?????-???

    ??'????????????????????????????????????????????o???????????????-?????????o????

  • Registrator ?3?????

    江苏快三开奖结果?????????????????o????????o????????1??????????3?????-?????????3???????3???????????

  • 江苏快三开奖结果Health Checker ????o????????

    江苏快三开奖结果???????????????|????o????1??????????3?????-??????????'???????????

  • 江苏快三开奖结果Load balancer '??????????

    ????????????????????????a???????????



???o? 2018-05-04 16:07 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/04/24/215601.html???o????o?Tue, 24 Apr 2018 04:13:00 GMThttp://www.598club.com/jinq0123/archive/2018/04/24/215601.htmlhttp://www.598club.com/jinq0123/comments/215601.htmlhttp://www.598club.com/jinq0123/archive/2018/04/24/215601.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215601.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215601.htmlPrometheus????????????????

(???o?????????? 2018.4)

??????????????????????????????????

scrape_configs:
  - job_name: 'prometheus'

    static_configs:
      - targets: ['localhost:9090', 'localhost:9100']
        labels:
          group: 'prometheus'

??'??1?-??????????????????????? SIGHUP |????????????????????

Prometheus ???????o????????????????????????????? consul, dns, kubernetes, file ?-??-?????????o????????????????????
?????-??????????????????????????????????????

????|? /root/prometheus/prometheus.yml ??????|???????

global:
  scrape_interval: 15s
  evaluation_interval: 15s
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['127.0.0.1:9090', '127.0.0.1:9100']
        labels:
          group: 'prometheus'
  - job_name: 'test'
    file_sd_configs:
      - files: ['/etc/prometheus/test_sd_config/*.yml']
        refresh_interval: 5s

?? docker ????? prometheus:

docker run -d --net=host \
  -v /root/prometheus:/etc/prometheus \
  --name prometheus-server \
  prom/prometheus

?????o /root/prometheus/test_sd_config/test.yml ?|????

- targets: [ "192.168.93.192:8080" ]
  labels:
    group: "my_test_group"

5s????????a??????? test.yml ?1????????????????????
?????????????????Prometheus 9090 ??????,
?????? Status ??-??? Configuration, Targets, Service Discovery,
??????????????????????????????


???o? 2018-04-24 12:13 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/04/19/215597.html???o????o?Thu, 19 Apr 2018 05:52:00 GMThttp://www.598club.com/jinq0123/archive/2018/04/19/215597.htmlhttp://www.598club.com/jinq0123/comments/215597.htmlhttp://www.598club.com/jinq0123/archive/2018/04/19/215597.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215597.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215597.htmlDocker????Prometheus???Grafana

(???o?????????? 2018.4)

Prometheus??????????????o????????'??????????
??????????? http://www.katacoda.com/ ??????????Docker????Prometheus???Grafana.
????'? Grafana ????????????????-?a?|???????

1. ?????? prometheus.yml

global:
  scrape_interval:     15s
  evaluation_interval: 15s
scrape_configs:
  - job_name: 'prometheus'

    static_configs:
      - targets: ['localhost:9090', 'localhost:9100']
        labels:
          group: 'prometheus'

localhost ???????????????????? 127.0.0.1
          
2. ???? prometheus

docker run -d --net=host \
  -v /root/prometheus.yml:/etc/prometheus/prometheus.yml \
  --name prometheus-server \
  prom/prometheus
 
3. ???? Node Exporter

docker run -d -p 9100:9100 \
-v "/proc:/host/proc" \
-v "/sys:/host/sys" \
-v "/:/rootfs" \
--net="host" \
--name=prometheus \
quay.io/prometheus/node-exporter:v0.13.0 \
  -collector.procfs /host/proc \
  -collector.sysfs /host/sys \
  -collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"

4. ???? Grafana
 
  docker run -d --name=grafana -p 3000:3000 grafana/grafana
 
??o?????????? admin/admin

5. ???????????o?????1?????????a????

Add Data Sources ->
Name: Prometheus
Type: Prometheus
URL: http://1.2.3.4:9090
Access: proxy
Save & Test...

Create Import ->
Grafana.com Dashboard: 22





???o? 2018-04-19 13:52 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/04/13/215587.html???o????o?Fri, 13 Apr 2018 07:41:00 GMThttp://www.598club.com/jinq0123/archive/2018/04/13/215587.htmlhttp://www.598club.com/jinq0123/comments/215587.htmlhttp://www.598club.com/jinq0123/archive/2018/04/13/215587.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215587.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215587.htmlgrpc-lua ?o???

(???o?????????? 2018.4)

grpc-lua (http://github.com/jinq0123/grpc-lua) ??? grpc ??? lua ???????o????
?o????o? luapbintf , ?????|??????????????????'???????? proto ?????????

?|????
    -- Sync request.
    local request = { name = "world" }
    local response = assert(stub:sync_request("SayHello", request))
    print("Greeter received: " .. response.message)

?????'????o?????????? examples ?????????

???????????????????????????????-????????-???????

?? examples/conan_install.bat.example ???? .example ??????????????????????
??????????????????????o?. ?????????? conan ????????????? (http://docs.conan.io/en/latest/installation.html)???
????|?????? git ??????????????o grpc ????-??o???|????????????

conan_install.bat ??????????????????????o????????1??????????????????????????? .conan/data/???
???????-????'? lua-cpp.exe, lua-cpp.dll, luapbintf.dll, grpc_lua.dll ?1???????? examples/helloworld/ ????????????

???????? helloworld ??????????????????? run_server.bat ??? run_client.bat ????????

?2???????????????????????'??????????????
grpc-lua ??????????o???Windows???????o????http://download.csdn.net/download/jq0123/10346554
grpc-lua ?o??? CentOS 7.4 ???????o??????????http://download.csdn.net/download/jq0123/10346003

CentOS 7.4 ?????????

[jinqing@localhost helloworld]$ ls
greeter_client.lua   grpc_lua.so       lua-cpp         run_server.bat
greeter_server.lua   helloworld.proto  luapbintf.so
greeter_service.lua  liblua-cpp.so     run_client.bat
[jinqing@localhost helloworld]$ ./lua-cpp greeter_server.lua
Server listening on 0.0.0.0:50051
Got hello from world
Got hello from world

[jinqing@localhost helloworld]$ ./lua-cpp greeter_client.lua
Greeter received: Hello world
Async greeter received: Hello world
[jinqing@localhost helloworld]$

[jinqing@localhost route_guide]$ ./lua-cpp route_guide_server.lua
RecordRoute reader end.
RouteChat reader end.

[jinqing@localhost route_guide]$ ./lua-cpp route_guide_client.lua
-------------- Sync get feature --------------
Found feature: {
...


???o? 2018-04-13 15:41 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/04/08/215577.html???o????o?Sun, 08 Apr 2018 07:17:00 GMThttp://www.598club.com/jinq0123/archive/2018/04/08/215577.htmlhttp://www.598club.com/jinq0123/comments/215577.htmlhttp://www.598club.com/jinq0123/archive/2018/04/08/215577.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215577.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215577.html?? DocFetcher ?????????'?

(???o?????????? 2018.4)

???????? Notepad++ ????????????'?????2?????'?????????????????'??????-????????????????

?? DocFetcher ???????o?????????????'??o????????o????'??????????????'?????????3??o?????????

???????o?????a???????????o?'????????????????o????????????????????????????????-???'????????????'????


???o? 2018-04-08 15:17 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/03/10/215551.html???o????o?Sat, 10 Mar 2018 10:03:00 GMThttp://www.598club.com/jinq0123/archive/2018/03/10/215551.htmlhttp://www.598club.com/jinq0123/comments/215551.htmlhttp://www.598club.com/jinq0123/archive/2018/03/10/215551.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215551.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215551.html?????????????? Services-based ??? Cells-based ??????

(???o?????????? 2018.3)

???????????????????????????????????????????
http://blog.csdn.net/SmartTony/article/details/6842065
?????o?o?2?????????????????????????

* Services-based architecture ??o?o????????????????
* Cells-based architecture ??o?o?cell?????????

??o?o??????????????????????????????????????????????????????????????????o?????????????????
????o?o?cell???????????????????????Cell???????????????a????????????aCell????????????????????????

??o?o?????????????????????'??????????????????????a??? microservice ??? service mesh ?|?????????????????
??o?o????????????????????o???????????o??a????????1??????

??????????????????????-????o???????o?o?cell??????????????????????????????3????????
????????????????????3????????????o????????????????????????
???????????????????????????????????1?o???????????o????????????|?PK?1??o?????cell???????????

??????????????????????????????????3????????cell, ?????udp/kcp?????????????????
??????????????????????????Tcp?????3????????
???????????????????????????? gRPC.



???o? 2018-03-10 18:03 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/01/18/215477.html???o????o?Thu, 18 Jan 2018 13:28:00 GMThttp://www.598club.com/jinq0123/archive/2018/01/18/215477.htmlhttp://www.598club.com/jinq0123/comments/215477.htmlhttp://www.598club.com/jinq0123/archive/2018/01/18/215477.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215477.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215477.html??????????-???-???????'???

(???o?????????? 2018.1)

????'???????temporal perception???:??1???????????????-??????o?o??????????o?????????????????1?o?????????????????????
-- http://dict.youdao.com/w/temporal_perception

??????????'????????????????o??????
???????????????????????????????|?1??????'????????????????????????????o??????
?????o???????ao????????o????2????????????????????????????????ao???2??????????????????o?????????2???
???o??????????'?????????????o??????????'???????????2???????

This raises the problem of interaction between objects displayed in present time space (the player's avatar) and objects displayed in a past time space (remote characters, AI entities). One solution is to make the LCT vary according to the distance from the player's avatar. This idea is called temporal perception, or presentation time or sometimes local perception filters and comes from the analogy with the appearance of the stars in the sky: the farther the distance, the longer the time the light takes to come to us [Singhal-Zyda].

-- http://www.xlgps.com/article/99968.html ??|???????????????????????????????-

??????????????????????'???????????2?o?o??????|????????????????????????????????'????????
????a?|????????????'????????????(temporal perception filter)???
??????????????????????(local perception filter)???

??????????????????????????????????????????????1'????????????????????????1'???????????????

Local Perception Filter Demo
http://mikolalysenko.github.io/local-perception-filter-demo/


???o? 2018-01-18 21:28 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2018/01/06/215458.html???o????o?Sat, 06 Jan 2018 03:05:00 GMThttp://www.598club.com/jinq0123/archive/2018/01/06/215458.htmlhttp://www.598club.com/jinq0123/comments/215458.htmlhttp://www.598club.com/jinq0123/archive/2018/01/06/215458.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215458.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215458.html??o LiteIDE ?????????-????

(???o?????????? 2018.1)

"[Eclipse Mark Occurrences](http://www.eclipse.org/pdt/help/html/mark_occurrences.htm)"
????????????????????1????o?????-??????????-??????????
??????????-?????a?????????o???????????????????? GoClipse ?2???? "Mark Occurrences" ????????
VS code ????-????????

LiteIDE ??1?o?build???????????o???????????????????????????????-?????"Mark Occurrences"???

|??????????o??????????????????????????????2????????????'QColor', ??????o????
```c++
QColor markTypeColor(LiteApi::EditorNaviagteType type)
```

?????3???????????????????
```c++
    void insertNavigateMark(int line, LiteApi::EditorNaviagteType type, const QString &msg, const char* tag);
    void clearAllNavigateMark(LiteApi::EditorNaviagteType types, const char *tag);
```

??????????-???|???????????????????????-???????'??????????????????????o??????"find", ????????
```c++
if (!m_findExpression.isEmpty()) {
    if (!findInBlock(block,m_findExpression,pos,m_findFlags,cur)) {
        break;
    }
    ...
    painter.drawRoundedRect(offsetX+left,r.top()+l.y(),right-left,l.height(),3,3);
} else if (!m_selectionExpression.isEmpty()) {
    if (!findInBlock(block,m_selectionExpression,pos,QTextDocument::FindWholeWords,cur)) {
        break;
    }
    ...
    painter.drawRoundedRect(offsetX+left,r.top()+l.y(),right-left,l.height(),3,3);
}
```

??????????1??????????????o????????-???????? m_findExpression ??? m_selectionExpression ??'??1?????
????? 'updateNavigateMarks()'

```c++
void LiteEditorWidgetBase::setFindOption(LiteApi::FindOption *opt)
{
    ...
+   updateNavigateMarks(LiteApi::EditorNavigateFind);
    viewport()->update();
}
```

```c++
void LiteEditorWidgetBase::slotSelectionChanged()
{
    ...
        m_selectionExpression.setPattern(pattern);
+       updateNavigateMarks(LiteApi::EditorNavigateSelection);
        viewport()->update();
    ...
}
```

???????2??a?????????????
```c++
enum EditorNaviagteType{
    EditorNavigateNormal = 1,
    EditorNavigateWarning = 2,
    EditorNavigateError = 4,
    EditorNavigateReload = 8,
+   EditorNavigateFind = 16,
+   EditorNavigateSelection = 32,
    EditorNavigateBad = EditorNavigateWarning|EditorNavigateError
};
```

????'? `EditorNavigateWarning`, ??????????????????????'??1???????o???????2????????

```c++
const int PRIORITYLIST_LENGTH = 7;
const LiteApi::EditorNaviagteType MARKTYPE_PRIORITYLIST[PRIORITYLIST_LENGTH] = {
        ..., LiteApi::EditorNavigateFind, LiteApi::EditorNavigateSelection, ...
    };
...
inline QColor markTypeColor(LiteApi::EditorNaviagteType type) {
    switch(type) {
    ...
    case LiteApi::EditorNavigateNormal:
        return Qt::darkGreen;
    case LiteApi::EditorNavigateReload:
        return Qt::darkBlue;
    }
}
```

??'?????????????????o?????????????????'?????????????
```c++
// Update selections or find marks.
void LiteEditorWidgetBase::updateNavigateMarks(LiteApi::EditorNaviagteType type)
{
    clearAllNavigateMark(type, "");
    ...

    QTextDocument *doc = this->document();
    for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next())
    {
        if (!needToMarkBlock(it, type))
            continue;
        int lineNumber = it.blockNumber() + 1;
        insertNavigateMark(lineNumber, type, QString("%1: %2").arg(lineNumber).arg(it.text()), "");
    }
}

bool LiteEditorWidgetBase::needToMarkBlock(
    const QTextBlock &block, LiteApi::EditorNaviagteType type) const
{
    ...
    if (LiteApi::EditorNavigateFind == type)
        return findInBlock(block, m_findExpression, pos, m_findFlags, cur);
    if (LiteApi::EditorNavigateSelection == type)
        return findInBlock(block, m_selectionExpression, pos,
                           QTextDocument::FindWholeWords, cur);
    return false;
}
```

?2????1?????12???
```
Revision: 43f4954b0b802eccbbf451136be600bfcec71f27
Author: Jin Qing <jinq0123@163.com>
Date: 18.1.5 19:08:26
Message:
Add "Mark Occurrences" function that marks selections and findings.

----
Modified: liteidex/src/api/liteeditorapi/liteeditorapi.h
Modified: liteidex/src/plugins/liteeditor/liteeditorwidgetbase.cpp
Modified: liteidex/src/plugins/liteeditor/liteeditorwidgetbase.h
```

???o? 2018-01-06 11:05 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2017/12/25/215444.html???o????o?Mon, 25 Dec 2017 11:00:00 GMThttp://www.598club.com/jinq0123/archive/2017/12/25/215444.htmlhttp://www.598club.com/jinq0123/comments/215444.htmlhttp://www.598club.com/jinq0123/archive/2017/12/25/215444.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215444.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215444.htmlgRPC-go ???????????

(???o?????????? 2017.12)

??? example greeter ??1?????????????? SayHello() ?????????????????????????????????????????-????
???????????????????????-?????|????
```
λ go run greeter_client/main.go
2017/12/25 17:59:13 Greeting: Hello 'world' (prev '')
2017/12/25 17:59:15 Greeting: Hello 'world2' (prev 'world')
```

????????????????????????1??o???????????

```go
    r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: name})
    log.Printf("Greeting: %s", r.Message)
    time.Sleep(2 * time.Second)

    r, err = c.SayHello(context.Background(), &pb.HelloRequest{Name: name + "2"})
    log.Printf("Greeting: %s", r.Message)
    ...
```

??????????|???o?????a?????????-?????a?????????????????????o??????????????????????????-????????????????????
??????????o????????????????????????????????????|?????????????????????1????

?????????????o???????? StatsHandler ???1?????????????a stats.Handler ???????????
```
-    s := grpc.NewServer()
+    s := grpc.NewServer(grpc.StatsHandler(&statshandler{}))
```

statshandler ???????4??a??1?3??????a????2??a??????????3?????1?3????TagConn() ??? HandleConn(),
??|??2??a TagRPC() ??? HandleRPC() ???o?RPC?????, ???????o??o???

```go
type statshandler struct{}

// TagConn ??????????????????a????-????????-?????????????(????????????????o?????????1?????3??????????????).
// ????a????-??????a?????????????????????a??????????????
// ???????????????????????????-??????????o connCtxKey{}.
func (h *statshandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context {
    return context.WithValue(ctx, connCtxKey{}, info)
}

// TagRPC ??o??o.
func (h *statshandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context {
    return ctx
}

// HandleConn ????????????????????????????????????????????????????????????????.
func (h *statshandler) HandleConn(ctx context.Context, s stats.ConnStats) {
    tag, ok := getConnTagFromContext(ctx)
    if !ok {
        log.Fatal("can not get conn tag")
    }

    connsMutex.Lock()
    defer connsMutex.Unlock()

    switch s.(type) {
    case *stats.ConnBegin:
        conns[tag] = ""
        log.Printf("begin conn, tag = (%p)%#v, now connections = %d\n", tag, tag, len(conns))
    case *stats.ConnEnd:
        delete(conns, tag)
        log.Printf("end conn, tag = (%p)%#v, now connections = %d\n", tag, tag, len(conns))
    default:
        log.Printf("illegal ConnStats type\n")
    }
}

// HandleRPC ??o??o.
func (h *statshandler) HandleRPC(ctx context.Context, s stats.RPCStats) {
}
```

???????amap??????????????????????????????????????-?(?????a?????)??o??????????o??????????????????-????
?????o??????o?????????????????????a Mutex ???????????
?????????????????????? conns ??-??????????????3???????????

```go
var connsMutex sync.Mutex
var conns map[*stats.ConnTagInfo]string = make(map[*stats.ConnTagInfo]string)
```

getConnTagFromContext() ??????????????-????????????-????

```go
type connCtxKey struct{}

func getConnTagFromContext(ctx context.Context) (*stats.ConnTagInfo, bool) {
    tag, ok := ctx.Value(connCtxKey{}).(*stats.ConnTagInfo)
    return tag, ok
}
```

???????? SayHello() ??1??o?????????????-?????1????????????????????????-????

```go
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
    tag, _ := getConnTagFromContext(ctx)
    log.Printf("SayHello(), conn tag = (%p)%#v\n", tag, tag)

    connsMutex.Lock()
    defer connsMutex.Unlock()
    prev := conns[tag]
    conns[tag] = in.Name

    return &pb.HelloReply{Message: fmt.Sprintf("Hello '%s' (prev '%s')", in.Name, prev)}, nil
}
```

?????????a????????????????????????????????a????????????a??????????????o????????????

```
E:\Git\grpc-go\examples\helloworld (master)
λ go run greeter_server/main.go
2017/12/25 18:39:03 start
2017/12/25 18:39:11 begin conn, tag = (0xc042182040)&stats.ConnTagInfo{RemoteAddr:(*net.TCPAddr)(0xc0420818f0), LocalAddr:(*net.TCPAddr)(0xc0420818c0)}, now connections = 1
2017/12/25 18:39:11 SayHello(), conn tag = (0xc042182040)&stats.ConnTagInfo{RemoteAddr:(*net.TCPAddr)(0xc0420818f0), LocalAddr:(*net.TCPAddr)(0xc0420818c0)}
2017/12/25 18:39:13 SayHello(), conn tag = (0xc042182040)&stats.ConnTagInfo{RemoteAddr:(*net.TCPAddr)(0xc0420818f0), LocalAddr:(*net.TCPAddr)(0xc0420818c0)}
2017/12/25 18:39:13 begin conn, tag = (0xc0421ae200)&stats.ConnTagInfo{RemoteAddr:(*net.TCPAddr)(0xc0421de060), LocalAddr:(*net.TCPAddr)(0xc0421de030)}, now connections = 2
2017/12/25 18:39:13 SayHello(), conn tag = (0xc0421ae200)&stats.ConnTagInfo{RemoteAddr:(*net.TCPAddr)(0xc0421de060), LocalAddr:(*net.TCPAddr)(0xc0421de030)}
2017/12/25 18:39:15 SayHello(), conn tag = (0xc042182040)&stats.ConnTagInfo{RemoteAddr:(*net.TCPAddr)(0xc0420818f0), LocalAddr:(*net.TCPAddr)(0xc0420818c0)}
2017/12/25 18:39:15 SayHello(), conn tag = (0xc0421ae200)&stats.ConnTagInfo{RemoteAddr:(*net.TCPAddr)(0xc0421de060), LocalAddr:(*net.TCPAddr)(0xc0421de030)}
2017/12/25 18:39:17 SayHello(), conn tag = (0xc042182040)&stats.ConnTagInfo{RemoteAddr:(*net.TCPAddr)(0xc0420818f0), LocalAddr:(*net.TCPAddr)(0xc0420818c0)}
2017/12/25 18:39:17 SayHello(), conn tag = (0xc0421ae200)&stats.ConnTagInfo{RemoteAddr:(*net.TCPAddr)(0xc0421de060), LocalAddr:(*net.TCPAddr)(0xc0421de030)}
2017/12/25 18:39:19 end conn, tag = (0xc042182040)&stats.ConnTagInfo{RemoteAddr:(*net.TCPAddr)(0xc0420818f0), LocalAddr:(*net.TCPAddr)(0xc0420818c0)}, now connections = 1
2017/12/25 18:39:19 SayHello(), conn tag = (0xc0421ae200)&stats.ConnTagInfo{RemoteAddr:(*net.TCPAddr)(0xc0421de060), LocalAddr:(*net.TCPAddr)(0xc0421de030)}
2017/12/25 18:39:21 end conn, tag = (0xc0421ae200)&stats.ConnTagInfo{RemoteAddr:(*net.TCPAddr)(0xc0421de060), LocalAddr:(*net.TCPAddr)(0xc0421de030)}, now connections = 0
```


???o? 2017-12-25 19:00 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2017/12/07/215397.html???o????o?Thu, 07 Dec 2017 06:51:00 GMThttp://www.598club.com/jinq0123/archive/2017/12/07/215397.htmlhttp://www.598club.com/jinq0123/comments/215397.htmlhttp://www.598club.com/jinq0123/archive/2017/12/07/215397.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215397.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215397.html

asio ???????- yield


(???o?????????? 2017.12)


江苏快三开奖结果http://stackoverflow.com/questions/26127458/yielding-in-boost-asio-stackful-coroutine


江苏快三开奖结果Asio spawn() ???????o????????a???????????????-????????? async_read(..., yield), async_write(..., yield), ???????????????|??????????????????????(yield)?


asio::spawn(strand_, [this, self](asio::yield_context yield)
{
    while (!computationFinished)
    {
        computeSomeMore();
        yield; // WHAT SHOULD THIS LINE BE?
    }
}


?-??????????

iosvc.post(yield);


?????????????????

iosvc.poll_one();

iosvc.poll();


江苏快三开奖结果?o?????? post(yield) ???????????


... polling the io_service avoids the context switch overhead, but unhandled exceptions from handlers will unwind and destroy the coroutine.




???o? 2017-12-07 14:51 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2017/11/28/215377.html???o????o?Tue, 28 Nov 2017 10:47:00 GMThttp://www.598club.com/jinq0123/archive/2017/11/28/215377.htmlhttp://www.598club.com/jinq0123/comments/215377.htmlhttp://www.598club.com/jinq0123/archive/2017/11/28/215377.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215377.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215377.html?? Lile ?????o gRPC-go ??????

(???o?????????? 2017.11)

Lile ????????a??????????o? Go ?-???????????o gRPC ?????????
http://github.com/lileio/lile

????a??????? Prometheus, Zipkin ??? Google PubSub ?????????

go get -u github.com/lileio/lile/...
?????????????????????????1??????? bin/lile.exe, bin/protoc-gen-lile-server.exe.
??|??????|?????? protoc.exe.

??????o????????o users ?????????

E:\gopath\src\github.com
λ lile new jinq0123/users
Creating project in E:\gopath\src\github.com\jinq0123\users
Is this OK? [y]es/[n]o
y
.
├── server
│   ├── server.go
│   └── server_test.go
├── subscribers
│   └── subscribers.go
├── users
│   ├── cmd
│   │   ├── root.go
│   │   ├── serve.go
│   │   ├── subscribe.go
│   │   └── up.go
│   └── main.go
├── users.proto
├── Makefile
├── Dockerfile
├── .travis.yml
└── .gitignore

?????? Makefile, ??????????- protoc ?????????? $$GOPATH ??1??o %GOPATH%??????????

E:\gopath\src\github.com\jinq0123\users
λ protoc -I . users.proto --lile-server_out=. --go_out=plugins=grpc:%GOPATH%/src
2017/11/28 16:59:24 [Creating] server\read.go
2017/11/28 16:59:24 [Creating test] server\read_test.go

protoc-gen-lile-server.exe ???????? server\read.go, ??1?o? user.proto ??-?????1?3? Users::Read().
grpc????????????????? users.pb.go?????????????? grpc ????????????????????????

D:/Go/bin/go.exe install -v [E:/gopath/src/github.com/jinq0123/users/users]
github.com/jinq0123/users/users
??????: ????????o?????? 0.

?????'?????????????? user.exe.

???????????????????o????????????????

E:\gopath\src\github.com\jinq0123\users
λ users
A gRPC based service

Usage:
  users [command]

Available Commands:
  help        Help about any command
  serve       Run the RPC server
  subscribe   Subscribe to and process queue messages
  up          up runs both RPC and pubub subscribers

Flags:
  -h, --help   help for users

Use "users [command] --help" for more information about a command.

???-??????serve??????????????

E:\gopath\src\github.com\jinq0123\users
λ users serve
INFO[0000] Serving gRPC on :8000
INFO[0000] Using Zipkin Global tracer
INFO[0000] Prometheus metrics at :9000/metrics

http://localhost:9000/metrics ???????o

# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
...

?? grpc-lua ??????????????

E:\Git\grpc-lua\examples\helloworld (master)
λ lua-cpp.exe
Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
> package.path = "../../src/lua/?.lua;" .. package.path
> grpc = require("grpc_lua.grpc_lua")
> grpc.import_proto_file("users.proto")
> stub = grpc.service_stub("localhost:8000", "users.Users")
D1128 17:28:13.711000000  4612 dns_resolver.c:301] Using native dns resolver
> request = {id = "abcd"}
> response, err, cod = stub:sync_request("Read", request)
> cod
2
> insp = require("inspect")
> insp(resonse)
nil
> insp(err)
"not yet implemented"

??o????????????? "not yet implemented" ?????????'??1?????????|???????

func (s UsersServer) Read(ctx context.Context, r *users.Request) (*users.Response, error) {
    // return nil, errors.New("not yet implemented")
    return &users.Response{Id: "Hello, " + r.Id}, nil
}

????????????

> response, err, cod = stub:sync_request("Read", request)
> err
Endpoint read failed
...
> response, err, cod = stub:sync_request("Read", request)
> err
nil
> insp(response)
{
  id = "Hello, abcd"
}


???o? 2017-11-28 18:47 ???????o
]]>
C++博客-金庆的专栏 http://www.598club.com/jinq0123/archive/2017/11/22/215364.html???o????o?Wed, 22 Nov 2017 02:45:00 GMThttp://www.598club.com/jinq0123/archive/2017/11/22/215364.htmlhttp://www.598club.com/jinq0123/comments/215364.htmlhttp://www.598club.com/jinq0123/archive/2017/11/22/215364.html#Feedback0http://www.598club.com/jinq0123/comments/commentRss/215364.htmlhttp://www.598club.com/jinq0123/services/trackbacks/215364.htmlprotobuf??-???????????o???????o?????oENUN_TYPE_UNSPECIFIED

(???o?????????? 2017.11)

Googol ????????? API Design ?????-???*.proto ??-???????????o????????o????o ENUN_TYPE_UNSPECIFIED???

http://mp.weixin.qq.com/s?__biz=MzA5ODg4Mzk2OQ==&mid=2247483705&idx=1&sn=cc2ffef9ac431510c1791dbe6e774b85

The first value should be named ENUM_TYPE_UNSPECIFIED as it is returned when an enum value is not explicitly specified.

enum FooBar {
  // The first value represents the default and must be == 0.
  FOO_BAR_UNSPECIFIED = 0;
  FIRST_VALUE = 1;
  SECOND_VALUE = 2;
}

????????protobuf??-???????????o???????o?????oUNKNOWN
http://blog.csdn.net/jq0123/article/details/52219597


???o? 2017-11-22 10:45 ???????o
]]>