Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Can Time Ticks uniquely identify IIS requests?

Reply
Thread Tools

Can Time Ticks uniquely identify IIS requests?

 
 
Tim_Mac
Guest
Posts: n/a
 
      09-11-2006
hi,
i'm generating PDF files from crystal reports in my .Net 1.1 web site, and
saving them to disk for the user to download in their own time.

the format i'm currently using is: FileName_<DateTime.Now.Ticks>.PDF

there is a relatively low level of concurrent users on this site, but i am a
little concerned that two requests could happen within the same tick,
resulting in a filename clash and overwrite. is this possible? the docs
say a tick is 100 nanoseconds, which is a very short time i know. i have a
reasonable understanding of memory and disk access times, and the IIS/.Net
request life cycle, which would tell me that because disks are so relatively
slow, being measured in milliseconds, that IIS couldn't perform two
synchronous writes in the same tick. my nagging doubt is that two
simultaneous requests could run to the point in code where the file names
are calculated within the same tick, and then the disk I/O could be
executed.

i like having the Ticks in the file name because it is somewhat useful to me
that they are sequential. but if it is at all risky then i would change to
using a GUID in the filename.

any ideas? i know this is overkill to be concerned like this but i'm
interested anyway
many thanks in advance

tim mackey


 
Reply With Quote
 
 
 
 
Laurent Bugnion
Guest
Posts: n/a
 
      09-11-2006
Hi,

Tim_Mac wrote:
> hi,
> i'm generating PDF files from crystal reports in my .Net 1.1 web site, and
> saving them to disk for the user to download in their own time.
>
> the format i'm currently using is: FileName_<DateTime.Now.Ticks>.PDF
>
> there is a relatively low level of concurrent users on this site, but i am a
> little concerned that two requests could happen within the same tick,
> resulting in a filename clash and overwrite. is this possible? the docs
> say a tick is 100 nanoseconds, which is a very short time i know. i have a
> reasonable understanding of memory and disk access times, and the IIS/.Net
> request life cycle, which would tell me that because disks are so relatively
> slow, being measured in milliseconds, that IIS couldn't perform two
> synchronous writes in the same tick. my nagging doubt is that two
> simultaneous requests could run to the point in code where the file names
> are calculated within the same tick, and then the disk I/O could be
> executed.


If you want to avoid concurrent access to a critical resource (in that
case, that would be the clock), you must use the lock statement. For
example, you could use a class to generate the file names and save the
files, and enclose the critical section in

lock ( this )
{
// ...
}

This will ensure a sequential execution.

However, the requests will be processed in sequential order too, so the
risk is zero IMHO.

If you really, really want to make sure that the ID is unique *and*
incrementing, why don't you simply add an index?

private static long lIndexOfFile = 0;

and then

string strFileName = "FileName_"
+ DateTime.Now.Ticks + lIndexOfFile++ + ".PDF";

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      09-12-2006
Hi Tim,

I would recommend to use GUID in the filename since DateTime.Now.Ticks is
not guaranteed to be unique.

By the way, is it supported in Crystal Reports to write the generated PDF
file to a stream instead of a file? If it's supported, then you may write
the PDF output the ASP.NET Response's output stream directly without using
a temporary file. Since Crystal Reports is not supported by Microsoft (see
http://support.microsoft.com/kb/100368/en-us for more info), you may have
to contact Crystal Reports for it.

Sincerely,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Tim_Mac
Guest
Posts: n/a
 
      09-12-2006
hi,
Laurent, thanks for the tip on using lock, i hadn't considered that
approach.
i think i'll just go with the GUIDs as Walter has suggested. it will give me
slightly better security in terms of malicious users trying to guess the URL
of a temp file. i clear them out every day with a script but even still, my
user population isn't very trustworthy!

Walter i was originally streaming the exported Crystal Reports to the Http
response as you suggested, but i found that very large reports (1000 page
PDFs) caused major problems both on server and client, hanging requests etc.
since i moved to a file based approach i have not had any of these problems
so i trust it a lot more. it also allows users to download the file in
their own time, i can show the status message and provide a hyperlink to
download the file.

thanks again for your help.
tim


"Walter Wang [MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Tim,
>
> I would recommend to use GUID in the filename since DateTime.Now.Ticks is
> not guaranteed to be unique.
>
> By the way, is it supported in Crystal Reports to write the generated PDF
> file to a stream instead of a file? If it's supported, then you may write
> the PDF output the ASP.NET Response's output stream directly without using
> a temporary file. Since Crystal Reports is not supported by Microsoft (see
> http://support.microsoft.com/kb/100368/en-us for more info), you may have
> to contact Crystal Reports for it.
>
> Sincerely,
> Walter Wang ((E-Mail Removed), remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscripti...ult.aspx#notif
> ications. If you are using Outlook Express, please make sure you clear the
> check box "Tools/Options/Read: Get 300 headers at a time" to see your
> reply
> promptly.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscripti...t/default.aspx.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generated UPDATE statement. could not determine which columns uniquely identify the rows for "Customers" bazzer ASP .Net 8 03-23-2007 08:26 PM
Eclipse debugger: breakpoints, ticks, no ticks Lord0 Java 0 10-25-2006 08:07 AM
could not determine which columns uniquely identify the rows for ... bazzer ASP .Net 0 04-10-2006 11:09 AM
How do I uniquely identify a control? Alan Silver ASP .Net 6 02-24-2005 06:31 PM
The best way to uniquely identify anonymous visitors muser8@hotmail.com ASP .Net 2 07-26-2004 11:47 PM



Advertisments