Split words into caracters

Hi !

I don’t know if it is the right way to go, and I hope to hear from you
if it
is not.

My concern is about the selection of a file traversing a tree. I have a
bunch of hashed directories (dozens of millions) on different servers.
As for performance reasons, I would like to avoid having to many
sub-directories in the same directory.

I would rather have this scheme :
1234/5678/90AB/CDEF/1234/5678/90AB/CDEF/myfile
It would help proxying to the right server and so on.

Will the traverse be fast enought ? Every directory is approx 100kb
heavy
(really light).

But other than openresty, i didn’t see any implementation inside nginx
to
split any word or cookie. C is faster than lua, so it would be a good
bet.
Well, I think.

What is your word on it ?

Thanks !

Larry

Posted at Nginx Forum:

But other than openresty, i didn’t see any implementation inside nginx to
split any word or cookie.

You can possibly use rewrite Module ngx_http_rewrite_module (
Module ngx_http_rewrite_module )

There is also an example to rewrite /photos/123456 to something like
/path/to/photos/12/1234/123456.png

rr

yeah but it works when you have multiple words.

What do you mean by multiple words?

In my case, there is only one which is 1234567890…DEF (md5 → 32 chars)
m=1234567890…DEF
m[1] = 1
m[2] = 2

m[32] = F

A mere rewrite is impossible here…
It seems indeed,

Why not?

rewrite
“/path/(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})”
/realpath/$r1/$r2/$r3/$r4/$r5/$r6/$r7/$r8/$r9/$r10/$r11/$r12/$r13/$r14/$r15/$r16/$r17/$r18/$r19/$r20/$r21/$r22/$r23/$r24/$r25/$r26/$r27/$r28/$r29/$r30/$r31/$r32;

It looks somewhat ugly because of 32 variables (aso because you need to
use
named ones (since $10/$11 … wouldnt work)).
There are probably much better ways to do this, but as a proof of
concept it
works:

Request to http://someserver/path/aBcdfghjklqwertyuiopas1234567890 gets
rewritten/translated to:

2013/04/02 18:25:37 [error] 2032#0: *60 open()
“/www/realpath/a/B/c/d/f/g/h/j/k/l/q/w/e/r/t/y/u/i/o/p/a/s/1/2/3/4/5/6/7/8/9/0”
failed (2: No such file or directory), request: "GET
/path/aBcdfghjklqwertyuiopas1234567890

(obviously error since such file doesnt exist for me)

:slight_smile:

rr

You are right Reinis,

It first seemed tough to me but yeah, it works :slight_smile:

Thanks,

Larry

Posted at Nginx Forum:

yeah but it works when you have multiple words.

In my case, there is only one which is 1234567890…DEF (md5 → 32
chars)

And I would need the possibility to do

m=1234567890…DEF
m[1] = 1
m[2] = 2

m[32] = F

A mere rewrite is impossible here…
It seems indeed,

Larry

Posted at Nginx Forum: