PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Finding the first file in a dir, fast, for message queue.
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Finding the first file in a dir, fast, for message queue.

Réponse
 
LinkBack Outils de la discussion
Vieux 08/01/2008, 12h24   #1
Alex Maccaw
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Finding the first file in a dir, fast, for message queue.

I have a file based msg queue, and msgs are stored five folders down.

When a request for the next msg is received, I need to grab the first
file I can find, as fast as I can.

I've tried Dir.glob, and only selecting the first file. This however is
an awful way of doing it as it loads every file into memory, before
selecting the first.

A bit better is Find.find, which finds files incrementally. However,
this still takes about 0.005 seconds (I presume since it's also
'finding' directories').

Is there a faster way to do this?
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 08/01/2008, 13h03   #2
Robert Klemme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding the first file in a dir, fast, for message queue.

2008/1/8, Alex Maccaw <maccman@gmail.com>:
> I have a file based msg queue, and msgs are stored five folders down.
>
> When a request for the next msg is received, I need to grab the first
> file I can find, as fast as I can.
>
> I've tried Dir.glob, and only selecting the first file. This however is
> an awful way of doing it as it loads every file into memory, before
> selecting the first.
>
> A bit better is Find.find, which finds files incrementally. However,
> this still takes about 0.005 seconds (I presume since it's also
> 'finding' directories').
>
> Is there a faster way to do this?


You find 5ms when accessing the file system long? I'd say that's
pretty fast considering what you do (recursive search). I doubt you
will get much improvement as long as you always access the file system
for your search. If you know the change frequency of files then you
could store file system contents in memory and only update every n
seconds / minutes or whatever or have a background thread that
continuously updates your in memory representation.

Kind regards

robert


--
use.inject do |as, often| as.you_can - without end

  Réponse avec citation
Vieux 08/01/2008, 13h18   #3
Alex Maccaw
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding the first file in a dir, fast, for message queue

> You find 5ms when accessing the file system long? I'd say that's
> pretty fast considering what you do (recursive search). I doubt you
> will get much improvement as long as you always access the file system
> for your search. If you know the change frequency of files then you
> could store file system contents in memory and only update every n
> seconds / minutes or whatever or have a background thread that
> continuously updates your in memory representation.



Well, it's long compared to generating folder names, a guid, and writing
files. It means that I can publish about 1000 msgs per second on to my
queue, but only pull of 243 msgs per second.
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 08/01/2008, 13h22   #4
Robert Klemme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding the first file in a dir, fast, for message queue

2008/1/8, Alex Maccaw <maccman@gmail.com>:
> > You find 5ms when accessing the file system long? I'd say that's
> > pretty fast considering what you do (recursive search). I doubt you
> > will get much improvement as long as you always access the file system
> > for your search. If you know the change frequency of files then you
> > could store file system contents in memory and only update every n
> > seconds / minutes or whatever or have a background thread that
> > continuously updates your in memory representation.

>
>
> Well, it's long compared to generating folder names, a guid, and writing
> files. It means that I can publish about 1000 msgs per second on to my
> queue, but only pull of 243 msgs per second.


Here's another option: find all files and put them in a queue. Only
redo search when the queue is empty. This might pay off over all.

robert


--
use.inject do |as, often| as.you_can - without end

  Réponse avec citation
Vieux 08/01/2008, 14h25   #5
Alex Maccaw
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding the first file in a dir, fast, for message queue

Robert Klemme wrote:
> 2008/1/8, Alex Maccaw <maccman@gmail.com>:
>> files. It means that I can publish about 1000 msgs per second on to my
>> queue, but only pull of 243 msgs per second.

>
> Here's another option: find all files and put them in a queue. Only
> redo search when the queue is empty. This might pay off over all.
>
> robert


Yes, that's what I've done. Message polling is now the same speed as
publishing (so the overall speed is about 10000 msg per second). If you
interested, here's the queue:

http://code.google.com/p/sparrow
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h28.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12789 seconds with 13 queries