Programming/golang2023. 1. 3. 15:21

0.0.0.0:6060 으로 하면 외부에서도 접근 가능하게 설정이 가능하다.

근데 멀 눌러야 사용율이 잘 나올까...

 

import _ "net/http/pprof"

go func() {
    log.Println(http.ListenAndServe("localhost:6060", nil))
}()

[링크 : https://coralogix.com/blog/optimizing-a-golang-service-to-reduce-over-40-cpu/]

[링크 : https://pkg.go.dev/net/http/pprof]

'Programming > golang' 카테고리의 다른 글

golang reflect  (0) 2023.01.03
golang unsafe  (0) 2023.01.03
golang shared memory 모듈  (0) 2022.11.22
golang net.TCPConn  (0) 2022.10.07
golang 변수 타입 알아내기  (0) 2022.10.05
Posted by 구차니

현재 사용중인 컴퓨터(i5-10210U) 에서 해보니

2000개(기본값 기준)

27~32 fps svg

42~48 fps canvas

60~61 fps webgl(아마도.. 측정불가?)

 

10000개

6~7 fps svg

11~12 fps canvas

60~61 fps webgl(아마도.. 측정불가?)

 

[링크 : https://ahoak.github.io/renderer-benchmark/]

   [링크 : https://github.com/ahoak/renderer-benchmark]

 

최적화 방법에 따라 달라지지만

SVG < canvas < webGL 순서로 성능이 올라가는 듯.

 

[링크 : https://www.yworks.com/blog/svg-canvas-webgl]

[링크 : https://blog.scottlogic.com/2020/05/01/rendering-one-million-points-with-d3.html]

'Programming > javascript & HTML' 카테고리의 다른 글

자바스크립트 소수점 자르기  (0) 2023.03.13
Math.min.apply()  (0) 2023.02.07
웹에서 f5 갱신 막기  (0) 2019.06.04
cose network graph  (0) 2019.06.03
HTTP 302 redirect  (0) 2019.04.26
Posted by 구차니
Programming/golang2022. 11. 22. 18:11

'Programming > golang' 카테고리의 다른 글

golang unsafe  (0) 2023.01.03
golang 웹 pprof  (0) 2023.01.03
golang net.TCPConn  (0) 2022.10.07
golang 변수 타입 알아내기  (0) 2022.10.05
cgo  (0) 2022.10.04
Posted by 구차니
Programming/openGL2022. 11. 17. 17:49

wayland / weston 에서 glReadPixels를 통해 읽어 오는게 실패해서 찾아보니

glUserProgram()을 하면 된다는데.. 문제는 어떤 컨텍스트의 정보를 어떻게 받아오냐 일 듯..

 

glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, output->width, output->height, GL_RGBA, GL_UNSIGNED_BYTE, data);

[링크 : https://github.com/ereslibre/wayland/blob/master/compositor/screenshooter.c]

 

It's an error to call anything but a very limited set of functions between glBegin and glEnd. That list is mostly composed of functions related to specifying attributes of a vertex (e.g., glVertex, glNormal, glColor, glTexCoord, etc.).

So, if your OpenGL implementation is following the OpenGL specification, glReadPixels should return immediately without executing because of being called within a glBegin/glEnd group. Remove those from around your calls, and glReadPixels should work as expected.

[링크 : https://stackoverflow.com/questions/19351568/glreadpixels-doesnt-work]

 

I figured it out. All I had to do was add glUseProgram(0) at the very end of the draw cylinder function. After more than 3 weeks of looking into this.

[링크 : https://computergraphics.stackexchange.com/questions/8354/why-is-glreadpixels-only-working-in-certain-cases]

 

glUseProgram — Installs a program object as part of current rendering state

[링크 : https://registry.khronos.org/OpenGL-Refpages/gl4/html/glUseProgram.xhtml]

[링크 : https://stackoverflow.com/questions/13546461/what-does-gluseprogram0-do]

'Programming > openGL' 카테고리의 다른 글

blender in openGL  (0) 2025.04.28
opengl glortho gluperspective  (0) 2023.08.28
openCV + openGL  (0) 2022.02.08
glMatrixMode()  (0) 2020.04.14
opengl superbible 3rd 리눅스 빌드 패키지  (0) 2020.04.08
Posted by 구차니
Programming/golang2022. 10. 7. 18:00

net.Listen() 으로 받은것을

sock.Accept()로 받아 어떤 FD에 저장이 되어서 처리되고 있나를 보고 싶은데

(왜 굳이 이게 필요한 진 묻지 말자. 걍 보고 싶었음)

 

아래와 같이 8000번 열고 nc localhost 8000 하면 접속이 가능하다.

그나저나 conn.File()은 없는 메소드라 나오고

conn.(*net.TCPConn).File()은 되는데 타입 캐스팅인가? 도대체 무슨 문법이지?

tcp_sock, err := net.Listen("tcp", ":8000")
if err != nil {
        fmt.Println(err)
}

for {
        conn, err := tcp_sock.Accept()
        if err != nil {
                fmt.Println(err)
                continue
        }
        fmt.Println(conn)
        fd, err := conn.(*net.TCPConn).File()
        if err != nil {
                fmt.Println(fd.Fd())
        }
        fmt.Println(reflect.TypeOf(conn))
        fmt.Println(conn.LocalAddr())
        fmt.Println(conn.RemoteAddr())
}
fmt.Println("done")
&{{0xc0000a0180}}
*net.TCPConn
127.0.0.1:8000
127.0.0.1:37690

위와 같이 출력된다. 왜 그러나 했더니 포인터 형태로 리턴되는건데, 이걸 출력하려면 unsafe를 써야 하는건가..

 

[링크 : https://pkg.go.dev/net#TCPConn.File]

[링크 : https://pkg.go.dev/os#File.Fd]

[링크 : https://pkg.go.dev/builtin#uintptr]

 

+

[링크 : https://pkg.go.dev/net#Conn]

 

Type assertions

[링크 : https://go.dev/tour/methods/15]

'Programming > golang' 카테고리의 다른 글

golang 웹 pprof  (0) 2023.01.03
golang shared memory 모듈  (0) 2022.11.22
golang 변수 타입 알아내기  (0) 2022.10.05
cgo  (0) 2022.10.04
golang unsafe package  (0) 2022.10.01
Posted by 구차니
Programming/golang2022. 10. 5. 23:44

 refelct 패키지의 reflect.TypeOf()를 통해 :=로 할당된 객체의 타입을 알아낼 수 있다.

package main

import (
    "fmt"
    "reflect"
)

func main() {

    tst := "string"
    tst2 := 10
    tst3 := 1.2

    fmt.Println(reflect.TypeOf(tst))
    fmt.Println(reflect.TypeOf(tst2))
    fmt.Println(reflect.TypeOf(tst3))

}
Hello, playground
string
int
float64

[링크 : https://stackoverflow.com/questions/20170275/how-to-find-the-type-of-an-object-in-go]

 

func TypeOf(i any) Type
TypeOf returns the reflection Type that represents the dynamic type of i. If i is a nil interface value, TypeOf returns nil.

[링크 : https://pkg.go.dev/reflect]

[링크 : https://pkg.go.dev/reflect#TypeOf]

'Programming > golang' 카테고리의 다른 글

golang shared memory 모듈  (0) 2022.11.22
golang net.TCPConn  (0) 2022.10.07
cgo  (0) 2022.10.04
golang unsafe package  (0) 2022.10.01
golang 의 장단점. 개인적인 생각  (2) 2022.09.28
Posted by 구차니
Programming/golang2022. 10. 4. 19:00

cgo

그나저나 얘 쓰면.. 크로스컴파일은 알아서 찾아서 하나?

 

포인트는 import "C"

그리고 C.함수명

package main

// typedef int (*intFunc) ();
//
// int
// bridge_int_func(intFunc f)
// {
// return f();
// }
//
// int fortytwo()
// {
//     return 42;
// }
import "C"
import "fmt"

func main() {
f := C.intFunc(C.fortytwo)
fmt.Println(int(C.bridge_int_func(f)))
// Output: 42
}

[링크 : https://pkg.go.dev/cmd/cgo]

[링크 : https://linsoo.pe.kr/archives/26740]

'Programming > golang' 카테고리의 다른 글

golang net.TCPConn  (0) 2022.10.07
golang 변수 타입 알아내기  (0) 2022.10.05
golang unsafe package  (0) 2022.10.01
golang 의 장단점. 개인적인 생각  (2) 2022.09.28
golang json/encoding marshal() unmarshal()  (0) 2022.09.28
Posted by 구차니
Programming/golang2022. 10. 1. 16:23

golang에 포인터는 지원하는데 산술연산자를 지원하지 않기에

unsafe가 필수인데.. 그렇다면.. golang은 포인터를 지원한다고 할 수 있는게 맞...나?

 

[링크 : https://stackoverflow.com/questions/32700999/pointer-arithmetic-in-go]

[링크 : https://medium.com/a-journey-with-go/go-what-is-the-unsafe-package-d2443da36350]

[링크 : https://pkg.go.dev/unsafe]

 

 

 

'Programming > golang' 카테고리의 다른 글

golang 변수 타입 알아내기  (0) 2022.10.05
cgo  (0) 2022.10.04
golang 의 장단점. 개인적인 생각  (2) 2022.09.28
golang json/encoding marshal() unmarshal()  (0) 2022.09.28
golang mac address 얻기  (0) 2022.09.28
Posted by 구차니
Programming/golang2022. 9. 28. 17:16

golang이 어쩔수 없이 쓰긴 하지만 마음에 들진 않는다 정도가 현재까지 결론

 

장점.

1. 멀티플랫폼 지원.

> 리눅스건 맥이건 윈도우건 GOOS= 라는 선언 하나 주면 아주 간단하게 크로스빌드가 된다.

2. 정적 바이너리 생성(기본 값)

> 양날의 검. 물론 hello world 하나 출력하는데 2MB 정도 먹고 몇가지 모듈들을 불러오면 기하급수적으로 늘지만

> 별다른 의존성 라이브러리 없이 독립적으로 빌드해서 실행가능한 단일 파일 하나만 복사하면 되는 건

> 임베디드에서 관리의 편의성을 제공함

3. 컴파일 언어

> node.js나 python과 같이 메모리 관리 불가능(?)한 실행환경이 아닌 컴파일 된 바이너리가 실행되는 것.

> 상업 프로그램, 배포환경, 임베디드라는 조건에서는 오히려 장점

4. net/http 등과 같은 고수준 라이브러리 제공

> c로도 curl 을 쓰면 REST 구현은 가능하지만 기본 라이브러리로 푸짐하게 제공하는 golang이 편하긴 하다.

 

단점.

1. 고정된 문법. 왜 내 마음대로 괄호 위치를 못 하냐고!!!

> c로는 warning 뜰만한 것도 죄다 error로 중단되고, 사용하지 않는 변수 있다고 빌드 에러

> 게다가 if () { 식으로 마치 python 처럼 indent가 문법에서 강요되는 느낌이라 드럽게 거부감이 가시질 않음)

2. IDE 가 약함. vi로 하려면 어우.. 다 외우지 않으면 더 귀찮..

> 방대한 라이브러리를 제공하는 신형 언어들의 득과 실이긴 하지만.. vscode에서 잘 지원되려나

> 외부 라이브러리 등에 대한 자동 완성을 얼마나 지원하는지 테스트는 해봐야 할 듯.

3. npm이나 pip 같은 중앙관리 되는 라이브러리 저장소 부재

> 언어의 발달이 빠른 시기라 라이브러리 버전 문제와 엮여 구버전 소스 빌드가 쉽지 않음

> 게다가 npm 처럼 얼마나 인기있고 숙성된 라이브러리인지 간접적으로 예측할 지표가 없어서

> 매번 검색해서 누군가의 소스를 써야 하는 불안함을 지울 수 없음

4. 문서 부족. tour of go 정도로는 어림도 없다.

> effective go 정도는 봐야 하지 않나 싶은데, 그런 문서를 찾는 것 자체가 어떻게 보면 접근성 측면에서 최악.

> 꼰대가 되서(?!) html 보단 pdf로 된 걸 받고 싶은데 그런 것도 없고

> 어떤 언어를 하나 배우는데 있어서 학습 커브 상승에 상당히 일조하는 부족한 문서

5. 자동화.

> 양면의 날이긴 하지만 자동화로 인해서 자동화 돌리기 위한 구조를 알아야 하는 문제가 발생

> 부족한 문서와 음의 시너지를 일으킴. go build . 으로 빌드는 가능하지만 도대체 어떻게 묶일지

> 빌드 하려면 기본적으로 패키지 이해를 해야 한다. 근데 문서들도 자세한 설명은 없다는게 함정.

 

 

 

결론

특정 환경에서 어쩔수 없는 선택지 라는 수준의 언어. 

좋다 나쁘다를 떠나서 내 취향은 아니지만 웹 서비스를 구동하기에는 임베디드에서 이 만한 녀석은 없다는게 슬프다.

 

[링크 : https://covenant.tistory.com/204]

[링크 : https://simplear.tistory.com/8]

'Programming > golang' 카테고리의 다른 글

cgo  (0) 2022.10.04
golang unsafe package  (0) 2022.10.01
golang json/encoding marshal() unmarshal()  (0) 2022.09.28
golang mac address 얻기  (0) 2022.09.28
golang method  (0) 2022.09.27
Posted by 구차니
Programming/golang2022. 9. 28. 16:45

encoding/json 의 json.Unmarshal() 이나 json.Marshal()은 특이(?)하게도

구조체의 변수가 대문자여야 변환을 해준다.

어떤 버전이 그런 영향을 주는건진 모르겠지만.. 참고해야 할 듯..

 

package main

import (
                "net"
                //      "net/http"
                "fmt"
                "encoding/json"
        _       "io"
                "os"
       )

const conf_file = "config.json"
const server_url = "https://localhost"

type Config struct {
        Server  string
}

func main() {
        var config Config

        conf, err := os.ReadFile(conf_file)
        if err != nil {
                fmt.Println(err)
                fmt.Println("create default configuration file")

                config.Server = server_url
                jsonbyte, _ := json.Marshal(config)
                fmt.Println(config)
                fmt.Println(jsonbyte)
                os.WriteFile(conf_file, jsonbyte, 0644)
        }
        fmt.Println(conf)
        err = json.Unmarshal(conf, &config)
        fmt.Println(config)

        fmt.Println("*** Client start ***")
        temp, _ := net.InterfaceByName("enp0s25")
        mac := temp.HardwareAddr.String()
        fmt.Println(mac)
}

 

[링크 : https://www.joinc.co.kr/w/man/12/golang/json]

[링크 : https://jeonghwan-kim.github.io/dev/2019/01/18/go-encoding-json.html]

[링크 : http://golang.site/go/article/104-JSON-사용]

 

[링크 : https://pkg.go.dev/encoding/json]

'Programming > golang' 카테고리의 다른 글

golang unsafe package  (0) 2022.10.01
golang 의 장단점. 개인적인 생각  (2) 2022.09.28
golang mac address 얻기  (0) 2022.09.28
golang method  (0) 2022.09.27
go mod init 과 go build  (0) 2022.09.27
Posted by 구차니