Skip to content

[info] socket buffer #325

Open
Open

Description

@yechoi42
        int option;
        int rn;
        rn = sizeof(int);
        getsockopt(this->m_client_socket, SOL_SOCKET, SO_SNDBUF, &option, (socklen_t *)&rn);
        std::cout << "SIZE OF SOCKET1:::  " <<option << std::endl;
        option = option * 2;
        setsockopt(this->m_client_socket, SOL_SOCKET, SO_SNDBUF, &option, (socklen_t)rn);
        getsockopt(this->m_client_socket, SOL_SOCKET, SO_SNDBUF, &option, (socklen_t *)&rn);
        std::cout << "SIZE OF SOCKET2:::  " <<option << std::endl;
        sleep(2);

위와 같은 코드를 acceptSocket에서 accept() 한 이후 넣어두면

SIZE OF SOCKET1:::  146988
SIZE OF SOCKET2:::  293976

이렇게 나옵니다. option값을 조정해서 buff를 늘릴 수 있어요.

참고: https://www.joinc.co.kr/w/Site/Network_Programing/AdvancedComm/SocketOption

Activity

  1. yechoi42 commented on Apr 23, 2021

    @yechoi42
    MemberAuthor

    최대 버퍼수는 OS를 타는 듯합니다. 일단 기존 linux에서 최대 버퍼를 알아보는 방식이 맥에선 먹히진 않았고요. 아래는 IBM 자료라 확실하지 않네요.

    SO_SNDBUF
    Allows you to set the size of the send buffer to a value to suit your application needs. The minimum size is 512 bytes and the maximum size is 1048576 bytes.

    SO_RCVBUF
    Allows you to set the size of the receive buffer to a value to suit your application needs. The minimum size is 512 bytes. The maximum size is 1048576 bytes.

    참고 : https://www.ibm.com/docs/en/ztpf/1.1.0.14?topic=functions-setsockopt-set-options-associated-socket

  2. yechoi42 commented on Apr 23, 2021

    @yechoi42
    MemberAuthor

    맥에선 이거 같네요. sudo 명령어가 필요합니다.

    Tuning TCP for Mac OS X
    Mac OS X has a single sysctl parameter, kern.ipc.maxsockbuf, to set the maximum combined buffer size for both sides of
    a TCP (or other) socket. In general, it can be set to at least twice the BDP. E.g:

    sysctl -w kern.ipc.maxsockbuf=8000000
    

    The default send and receive buffer sizes can be set using the following sysctl variables:

    sysctl -w net.inet.tcp.sendspace=4000000
    sysctl -w net.inet.tcp.recvspace=4000000
    

    If you would like these changes to be preserved across reboots you can edit /etc/sysctl.conf


    첫번째 명령어는 이미 버퍼가 충분해서 안했고

    kern.ipc.maxsockbuf: 8388608
    

    아래 두 명령어는 적용해봤습니다.

    net.inet.tcp.recvspace: 131072 -> 4000000
    net.inet.tcp.sendspace: 131072 -> 4000000
    

    (밑에서의 문제로 버퍼크기를 8000000으로 늘리려고 시도해봤는데 크다고 거절하네요. 키우는 데 내부 한계가 있나봐요. 일단 6000000으로 더 키워봄. )

    참고: Enabling High Performance Data Transfers
    참고: Performance Tuning the Network Stack on Mac OS X Part 2

  3. yechoi42 commented on Apr 23, 2021

    @yechoi42
    MemberAuthor

    버퍼를 조정해준 효과가 있긴 한 것 같아요.
    원랜 첫번째 youpi.bla도 malformed chunked error가 떴었는데,
    조정한 이후론 마지막 테스트 케이스까지 실행되긴 합니다.
    성공은 못했지만요. 특이하게 이런 에러가 뜨면서 실패했습니다. 더 늘려줘야 하나 싶은 부분...

    Test multiple workers(20) doing multiple times(5): Post on /directory/youpi.bla with size 100000000
    FATAL ERROR ON LAST TEST: Post http://localhost:8080/directory/youpi.bla: write tcp 127.0.0.1:52028->127.0.0.1:8080: write: no buffer space available
    

    +)더 늘려줘봤어요. net.inet.tcp.recvspace, sendspace 6000000/ kern.ipc.maxsockbuf: 15000000으로. 그런데도 같은 에러가 뜨네요.

    +)연결이 너무 많은 경우 이런 에러가 나타날 수 있다고 하네요( This is an error message triggered by the operating system where there are too many TCP/IP network connections.)
    +) 그 밖에 이유에 대한 짐작들(메모리부족, max 파일이 적어서, 프로세스 워커를 늘려봐라...)
    +) 누가 껐다 키라길래 껐다 켰더니 해결됨;;;

  4. yechoi42 commented on Apr 23, 2021

    @yechoi42
    MemberAuthor

    저희가 테스트를 반복하면, 성공률이 올라가잖아요. 그 가설로 시스템이 알아서 버퍼를 조절해주는 게 아닐까, 얘기드렸었는데요. 실제로 그런 일을 해줍니다. buffer auto-tuning이라는 키워드로 검색해보면 관련 내용을 찾아볼 수 있습니다.

    TCP auto-tuning’s insight was to let the TCP stack participate in setting the size of TCP buffers. In the past 10 years, most major operating systems have added TCP auto-tuning to their TCP network stacks. Linux as of 2.6, Windows as of Vista, Mac OS X as of 10.5.
    참고: http://neurocline.github.io/dev/2015/11/12/tcp-auto-tuning.html

    아래 글을 한번 읽어보면 좋을 것 같아요. 오토 튜닝에 대해 지나가듯 언급을 하고 있기도 하고 우리가 버퍼 수를 늘려야 할 근거가 될 수 있는 이야기를 하고 있어요. 튜닝하는 방법에 대해선 윗윗 댓글의 참고글을 참고!

    리눅스 서버의 TCP 네트워크 성능을 결정짓는 커널 파라미터 이야기 - 1편
    https://meetup.toast.com/posts/53

  5. hochan222 commented on Apr 24, 2021

    @hochan222
    Member

    좋은 글들 잘 읽었습니다. 많은 것을 배워갑니다. 감사합니다. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions