Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7908221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:50:05+00:00 2026-06-03T11:50:05+00:00

I have a network daemon which receives messages of a fixed length (44 Bytes)

  • 0

I have a network daemon which receives messages of a fixed length (44 Bytes) on a TCP socket.

I am trying to determine what the best length in bytes I should be reading with sysread is. I can of course do a loop that does a sysread for 44 bytes, but I’d like to come up with an optimal size.

I can see an advantage to not having say, a megabyte worth of data to do substr on, but I can also see why doing a thousand sysread calls can cause slowness.

Is there a good size recommendation for doing sysreads over the public internet?

Edit:
The script gets a bunch of the 44 byte messages, they are queued up.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T11:50:17+00:00Added an answer on June 3, 2026 at 11:50 am

    The larger the better! sysread will return as soon any bytes are available.

    Since you’re never guaranteed to get a whole message and since you’re never guaranteed to not have more than one message, you need to have a loop on the Perl side. Since you already have a loop on the Perl side, so you might as well get as much data as possible from the system in one go to avoid needless system calls.

    use constant READ_SIZE => 65*1024;
    
    my $buf = '';
    while (1) {
       my $rv = sysread($fh, $buf, READ_SIZE, length($buf));
       die if !defined($rv);
       last if !$rv;
    
       while ($buf =~ s/^(.{44})//s) {
          my $msg = $1;
          process_msg($msg);
       }
    }
    

    Pick a size and monitor $buf‘s size. If it often approaches READ_SIZE, increase READ_SIZE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a network software which uses UDP to communicate with other instances of
I'm designing an application which will have a network interface for feeding out large
I have a network of Java Threads (Flow-Based Programming) communicating via fixed-capacity channels -
You have multiple network adapters. Bind a UDP socket to an local port, without
I've installed ArchLinux with VB on MacOS. I have network problems, I cannot resolve
I have a network of blogs that I want to be able to do
I'm using php 5.2 with IIS7.5. I have a network share on a NAS
I have a social network type site (member site) I store a lot of
I have a complex network of objects being spawned from a sqlite database using
I have setup a network of brokers in activemq, how do i connect to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.