Skip to content

Reduce delay in tcp socket communication#7

Merged
MarioIvancik merged 3 commits intomainfrom
BAF-1122/optimizations
Jul 24, 2025
Merged

Reduce delay in tcp socket communication#7
MarioIvancik merged 3 commits intomainfrom
BAF-1122/optimizations

Conversation

@MarioIvancik
Copy link
Copy Markdown
Contributor

@MarioIvancik MarioIvancik commented Jul 18, 2025

https://youtrack.bringauto.com/issue/BAF-1122/Module-Gateway-performance

Summary by CodeRabbit

  • Chores

    • Updated internal version number to 1.1.3.
    • Updated ignored files to exclude Visual Studio Code workspace settings.
    • Clarified library inclusion instructions in documentation for CMake projects.
  • New Features

    • Improved network performance by disabling Nagle's algorithm for TCP connections, resulting in reduced latency.

@MarioIvancik MarioIvancik self-assigned this Jul 18, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 18, 2025

Walkthrough

The updates include adding .vscode/ to .gitignore, incrementing the client version in the CMake configuration from 1.1.2 to 1.1.3, modifying the socket connection logic in Context.cpp to set the TCP_NODELAY option disabling Nagle's algorithm, and clarifying README instructions for including the installed library in CMake projects.

Changes

File(s) Change Summary
.gitignore Added .vscode/ to ignored directories.
CMakeLists.txt Updated client version from 1.1.2 to 1.1.3.
source/Context.cpp Included <netinet/tcp.h> and set TCP_NODELAY socket option in connection methods (createConnection and reconnect).
README.md Updated CMake usage instructions to require both internal-client-shared and fleet-protocol-interface packages and link libraries accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Context
    participant OS/Network

    Client->>Context: createConnection()/reconnect()
    Context->>OS/Network: socket()
    OS/Network-->>Context: socket descriptor
    Context->>OS/Network: setsockopt(TCP_NODELAY)
    alt setsockopt fails
        Context-->>Client: return NOT_OK
    else setsockopt succeeds
        Context->>OS/Network: connect()
        OS/Network-->>Context: connection result
        Context-->>Client: return status
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10-15 minutes

Possibly related PRs

  • version tag 1.1.2 #6: Also updates the client version number in CMakeLists.txt, incrementing it to 1.1.2 prior to this PR's increment to 1.1.3.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4bab59a and 4fe6424.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • source/Context.cpp (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • source/Context.cpp
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch BAF-1122/optimizations

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
source/Context.cpp (2)

21-25: LGTM! TCP_NODELAY correctly implemented for performance improvement.

The TCP_NODELAY socket option is properly set to disable Nagle's algorithm, which will reduce latency by sending packets immediately instead of buffering small packets. This directly addresses the PR objective of reducing TCP socket communication delay.

The error handling is appropriate, and the positioning right after socket creation is correct.

For better portability, consider using void* instead of char* for the cast:

-    if (setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0) {
+    if (setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int)) < 0) {

Some systems may prefer void* (which is the implicit conversion), though the current implementation works on most Unix-like systems.


45-49: LGTM! Consistent TCP_NODELAY implementation in reconnect method.

The TCP_NODELAY option is correctly applied in the reconnect method as well, ensuring consistent behavior when the socket is recreated. The duplication is necessary and appropriate since both methods create new sockets.

For consistency with the previous suggestion, consider the same portability improvement:

-    if (setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0) {
+    if (setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int)) < 0) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2fcb4ed and 015d154.

📒 Files selected for processing (3)
  • .gitignore (1 hunks)
  • CMakeLists.txt (1 hunks)
  • source/Context.cpp (3 hunks)
🧰 Additional context used
🧠 Learnings (2)
CMakeLists.txt (4)
Learnt from: koudis
PR: bringauto/module-gateway#43
File: CMakeLists.txt:11-14
Timestamp: 2025-06-29T18:12:34.666Z
Learning: In the ModuleGateway project's CMakeLists.txt, compile definitions for version strings are intentionally set with escaped quotes using CMDEF_COMPILE_DEFINITIONS to produce compiler flags like `-DMODULE_GATEWAY_VERSION="1.3.3"`, ensuring the macro expands to a proper string literal in C++ code.
Learnt from: Mayt34
PR: bringauto/transparent-module#1
File: CMakeLists.txt:46-66
Timestamp: 2024-10-03T11:51:48.708Z
Learning: In this project, using `GLOB_RECURSE` in `CMakeLists.txt` is preferred for source file listing to allow automatic inclusion of new source files without modifying the file.
Learnt from: Mayt34
PR: bringauto/transparent-module#1
File: CMakeLists.txt:46-66
Timestamp: 2024-10-09T05:03:50.249Z
Learning: In this project, using `GLOB_RECURSE` in `CMakeLists.txt` is preferred for source file listing to allow automatic inclusion of new source files without modifying the file.
Learnt from: koudis
PR: bringauto/packager#28
File: example/docker/fedora41/Dockerfile:20-21
Timestamp: 2025-01-21T11:34:52.410Z
Learning: Version pinning for the cmakelib repository in Dockerfiles is not required as per team preference.
.gitignore (2)
Learnt from: Mayt34
PR: bringauto/transparent-module#1
File: CMakeLists.txt:46-66
Timestamp: 2024-10-03T11:51:48.708Z
Learning: In this project, using `GLOB_RECURSE` in `CMakeLists.txt` is preferred for source file listing to allow automatic inclusion of new source files without modifying the file.
Learnt from: Mayt34
PR: bringauto/transparent-module#1
File: CMakeLists.txt:46-66
Timestamp: 2024-10-09T05:03:50.249Z
Learning: In this project, using `GLOB_RECURSE` in `CMakeLists.txt` is preferred for source file listing to allow automatic inclusion of new source files without modifying the file.
🔇 Additional comments (3)
.gitignore (1)

4-4: LGTM! Standard IDE configuration exclusion.

Adding .vscode/ to the gitignore is a best practice to prevent Visual Studio Code workspace settings from being tracked, consistent with the existing .idea/ exclusion.

CMakeLists.txt (1)

10-10: LGTM! Appropriate version bump for the TCP socket enhancement.

The version increment from 1.1.2 to 1.1.3 is appropriate for the TCP_NODELAY socket option addition, following semantic versioning for a minor enhancement.

source/Context.cpp (1)

11-11: LGTM! Required header for TCP_NODELAY option.

The inclusion of <netinet/tcp.h> is necessary for the TCP_NODELAY constant used in the socket option setting.

Comment thread source/Context.cpp Outdated
@koudis
Copy link
Copy Markdown
Member

koudis commented Jul 24, 2025

There are more things to this repo
Readme:

  • The readme is wrong - the name of the target is not valid anymore, I guess.
  • Use char8_t instead of char please (we are in C++ s ochar doe not require to by 1 byte)

@MarioIvancik MarioIvancik merged commit 7c1d291 into main Jul 24, 2025
1 check passed
@koudis koudis deleted the BAF-1122/optimizations branch October 17, 2025 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants