473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Random IO Read

Hi All

Below coding for generate a file. Do you know how to write a code for
random a a file for multi-user access ?

We want testing FileSystem IO performance.

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#define FAIL -1
#define BSIZE 8192
#define FSIZE 5000

int writeit(int);
int main(void)
{
if ( -1 == writeit(FSIZE)) printf("FILE OPERATION FAILED\n");
}

int writeit(int blocks)
{
char buf[BSIZE];
int fdes;
int i;
int written;
if ( (fdes = open("./testfile.bm",O_WRONLY|O_CREAT,0777)) < 0)
return FAIL;
for (i=0;i< blocks ; i++)
{
if (written = write(fdes,buf,BSIZE) != BSIZE) return FAIL;
}
return 0;
}
Jun 27 '08 #1
10 1712
moonhkt wrote:
Hi All

Below coding for generate a file. Do you know how to write a code for
random a a file for multi-user access ?

We want testing FileSystem IO performance.

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#define FAIL -1
#define BSIZE 8192
#define FSIZE 5000

int writeit(int);
int main(void)
{
if ( -1 == writeit(FSIZE)) printf("FILE OPERATION FAILED\n");
}

int writeit(int blocks)
{
char buf[BSIZE];
int fdes;
int i;
int written;
if ( (fdes = open("./testfile.bm",O_WRONLY|O_CREAT,0777)) < 0)
return FAIL;
for (i=0;i< blocks ; i++)
{
if (written = write(fdes,buf,BSIZE) != BSIZE) return FAIL;
}
return 0;
}
You'll be better served in comp.unix.programmer as your code is UNIX
specific and hardly standard C.

Jun 27 '08 #2
On Thu, 24 Apr 2008 14:35:35 +0530, santosh <sa*********@gmail.com>
wrote:
>moonhkt wrote:
>Hi All

Below coding for generate a file. Do you know how to write a code for
random a a file for multi-user access ?
Ignoring your non-standard functions and headers, your problem seems
to be how to fill buf with BSIZE random char. One method would be to:
Change buf to unsigned char.
Call srand to seed the rand function.
In a loop, call rand and store some part of the int it returns in
the "current" element of buf.
>>
We want testing FileSystem IO performance.
Is it a reasonable concern that IO performance would be affected by
the bit patterns involved? Would the results be any different if buf
were filed with 0xa5? If there is a difference, is 5000 char enough
for it to be noticed (or measured)?
>>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#define FAIL -1
#define BSIZE 8192
#define FSIZE 5000

int writeit(int);
int main(void)
{
if ( -1 == writeit(FSIZE)) printf("FILE OPERATION FAILED\n");
}

int writeit(int blocks)
{
char buf[BSIZE];
int fdes;
int i;
int written;
if ( (fdes = open("./testfile.bm",O_WRONLY|O_CREAT,0777)) < 0)
return FAIL;
for (i=0;i< blocks ; i++)
{
if (written = write(fdes,buf,BSIZE) != BSIZE) return FAIL;
}
return 0;
}

You'll be better served in comp.unix.programmer as your code is UNIX
specific and hardly standard C.

Remove del for email
Jun 27 '08 #3
moonhkt wrote:
Hi All

Below coding for generate a file. Do you know how to write a code for
random a a file for multi-user access ?

We want testing FileSystem IO performance.
If you want to do that, use one of the many tools that have been
designed for this task.

--
Ian Collins.
Jun 27 '08 #4
On 24 Apr 2008 at 8:48, moonhkt wrote:
Below coding for generate a file. Do you know how to write a code for
random a a file for multi-user access ?
Why not read /dev/urandom ?

Jun 27 '08 #5
In article <sl*******************@nospam.invalid>,
Antoninus Twink <no****@nospam.invalidwrote:
>On 24 Apr 2008 at 8:48, moonhkt wrote:
>Below coding for generate a file. Do you know how to write a code for
random a a file for multi-user access ?

Why not read /dev/urandom ?
The OP indicated they wanted to test filesystem IO performance,
not /dev/urandom performance. When implemented at all, /dev/urandom
is not designed for high performance.

/dev/urandom is not even part of POSIX, let alone part of C.

--
"A scientist who cannot prove what he has accomplished,
has accomplished nothing." -- Walter Reisch
Jun 27 '08 #6
On 24 Apr 2008 at 18:52, Walter Roberson wrote:
In article <sl*******************@nospam.invalid>,
Antoninus Twink <no****@nospam.invalidwrote:
>>Why not read /dev/urandom ?

The OP indicated they wanted to test filesystem IO performance,
not /dev/urandom performance. When implemented at all, /dev/urandom
is not designed for high performance.
OK, then why not copy as many bytes from /dev/urandom as desired to a
file, then read that file?

Jun 27 '08 #7
In article <sl*******************@nospam.invalid>,
Antoninus Twink <no****@nospam.invalidwrote:
>On 24 Apr 2008 at 18:52, Walter Roberson wrote:
>In article <sl*******************@nospam.invalid>,
Antoninus Twink <no****@nospam.invalidwrote:
>>>Why not read /dev/urandom ?
>The OP indicated they wanted to test filesystem IO performance,
not /dev/urandom performance.
>OK, then why not copy as many bytes from /dev/urandom as desired to a
file, then read that file?
Because, as I pointed out earlier, /dev/urandom is not part of C
and is not even part of POSIX ?

--
"All human knowledge takes the form of interpretation."
-- Walter Benjamin
Jun 27 '08 #8
On 24 Apr 2008 at 19:51, Walter Roberson wrote:
In article <sl*******************@nospam.invalid>,
Antoninus Twink <no****@nospam.invalidwrote:
>>OK, then why not copy as many bytes from /dev/urandom as desired to a
file, then read that file?

Because, as I pointed out earlier, /dev/urandom is not part of C
and is not even part of POSIX ?
C and POSIX aren't sacred cows - use the best tool for the job. If the
OP's system *does* have /dev/urandom available, then that's a much
better option than reinventing the wheel.

Jun 27 '08 #9
In article <sl*******************@nospam.invalid>,
Antoninus Twink <no****@nospam.invalidwrote:
>C and POSIX aren't sacred cows - use the best tool for the job. If the
OP's system *does* have /dev/urandom available, then that's a much
better option than reinventing the wheel.
If the OP is going to precreate the file and has /dev/urandom
then they very likely have /dev/random as well, which will create a
more random file, thus better testing the throughput limits on
links that have compression enabled. Not that /dev/random is
C or POSIX either, but for the original poster's purpose, /dev/urandom
isn't even the best tool on systems that have it.

For testing throughput limits on links that have compression enabled,
one does not even need true randomness, only sufficiently good
pseudo-randomness, such as using one of the portable implementations
of the Mersenne Twister algorithm.

--
"Do diddle di do,
Poor Jim Jay
Got stuck fast
In Yesterday." -- Walter De La Mare
Jun 27 '08 #10
On 24 Apr 2008 at 20:14, Walter Roberson wrote:
In article <sl*******************@nospam.invalid>,
Antoninus Twink <no****@nospam.invalidwrote:
>>C and POSIX aren't sacred cows - use the best tool for the job. If the
OP's system *does* have /dev/urandom available, then that's a much
better option than reinventing the wheel.

If the OP is going to precreate the file and has /dev/urandom
then they very likely have /dev/random as well, which will create a
more random file, thus better testing the throughput limits on
links that have compression enabled. Not that /dev/random is
C or POSIX either, but for the original poster's purpose, /dev/urandom
isn't even the best tool on systems that have it.

For testing throughput limits on links that have compression enabled,
one does not even need true randomness, only sufficiently good
pseudo-randomness, such as using one of the portable implementations
of the Mersenne Twister algorithm.
These two paragraphs seem to contradict each other. He's testing a file
system, so tiny differences in "randomness" are irrelevant - I agree.
Therefore he should use /dev/urandom, rather than waiting around while
/dev/random blocks waiting for more entropy to be generated.

Jun 27 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Phillo | last post by:
Hello, I'm new at Javascript, and have written a script for a series of random roll-over button images, but one thing I would like to add is a function that checks to make sure that there are no...
15
by: John Cassidy | last post by:
This has been driving me crazy. I've done basic C in school, but my education is mainly based on object oriented design theory where Java is our tool. For some reason, while helping a friend with a...
21
by: Ron Peterson | last post by:
In the following piece of code, which simply generates a sequence of (random) octal codes, I'm surprised by the apparent non-randomness of /dev/random. It's not noticeable unless RAND_LENGTH is...
9
by: Stu Banter | last post by:
Hi, On a previous question someone recommended using the System.Security.Cryptography to fill an array with strong random bytes. It works but I can't specify the max value of course.. I solved...
5
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible...
13
by: porterboy76 | last post by:
If you only use a 32 bit seed for a random number generator, does that mean you can only ever produce a maximum of 2^32 (approx 4 billion) different sequences? What about the Mersenne Twister,...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
1
by: Ben | last post by:
Is the following a known bug? $ python -U Python 2.4.4 (#1, Oct 23 2006, 13:58:18) on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent...
24
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me ...
16
by: raylopez99 | last post by:
For the public record. RL public void IterateOne() { Random myRandom = new Random(); //declare Random outside the iteration for (int j = 0; j < Max; j++) {
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.