Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sessions are so slow #47

Closed
zek opened this issue Aug 28, 2013 · 6 comments
Closed

Sessions are so slow #47

zek opened this issue Aug 28, 2013 · 6 comments

Comments

@zek
Copy link

zek commented Aug 28, 2013

He is the some results with and without
Session session = new Session(cgi);
scope(exit) session.commit();

without:
Server Software: Microsoft-IIS/8.0
Server Hostname: 127.0.1.1
Server Port: 80

Document Path: /index.rhs
Document Length: 28 bytes

Concurrency Level: 20
Time taken for tests: 1.438 seconds
Complete requests: 3000
Failed requests: 0
Write errors: 0
Total transferred: 801000 bytes
HTML transferred: 84000 bytes
Requests per second: 2086.28 #/sec
Time per request: 9.586 ms
Time per request: 0.479 [ms](mean, across all concurrent requests)
Transfer rate: 543.98 [Kbytes/sec] received

with:

Document Path: /index.rhs
Document Length: 28 bytes

Concurrency Level: 20
Time taken for tests: 21.989 seconds
Complete requests: 3000
Failed requests: 0
Write errors: 0
Total transferred: 982195 bytes
HTML transferred: 84000 bytes
Requests per second: 136.43 #/sec
Time per request: 146.591 ms
Time per request: 7.330 [ms](mean, across all concurrent requests)
Transfer rate: 43.62 [Kbytes/sec] received

why session is so slow? I looked that in PHP. PHP is not slow . Maybe you could know I am trying to make a web programming language like PHP. And I need SESSIONS. What is the reason of low speed. Are you going to make it faster?

Thanks

@theredhead
Copy link

I've barely looked through the code for Session (in web.d) and it seems to me at first glance the only thing negatively impacting performance is would be file IO. You could possibly get around that by using a database server of some sort, or even a faster harddisk or ssd...

FYI; I haven't actually benchmarked this with php, but I'd be impressed if you got better performance from php there. whichever way I look at it, processing > 1000 requests per minute is fast. so taking 22 seconds to process 3000 (roughly 9000 per minute!) is nowhere near slow imho.

@adamdruppe
Copy link
Owner

On Tue, Aug 27, 2013 at 09:25:51PM -0700, Talha Zekeriya Durmuş wrote:

why session is so slow? I looked that in PHP. PHP is not slow . Maybe you could know I am trying to make a web programming language like PHP. And I need SESSIONS. What is the reason of low speed. Are you going to make it faster?

Probably be because creating a new session writes to a file.

Did you test a PHP session where you saved a variable to it, not just creating it?
PHP's session_create doesn't actually save anything, whereas web.d's new Session
fills it with security tokens, so it does write to the file.

But if PHP is fast when saving variables too, maybe they use something other
than files.

Would you be ok with sessions going away when the app restarted? I could just
keep them in a big global variable.

I just pushed a new thing to web.d. Try compiling your thing with
-version=webd_memory_sessions

and see if it is any better. I got a 3x speedup using that on linux. Not sure how
reliable this is but not hitting files has got to help.

@zek
Copy link
Author

zek commented Aug 28, 2013

I have just tested this:

void handler(Cgi cgi) {
std.file.write("test.tmp","qweqwe");
return;
}

It processed 3000 request per second and that is almost near without file.write. So it is not about file writing thing. Slowness is relative with another thing.

And for the test things I am using apache ab application with that parameters:

c:\xampp\apache\bin>ab -c 10 -n 1000 http://127.0.0.1/

@adamdruppe
Copy link
Owner

On Wed, Aug 28, 2013 at 11:32:53AM -0700, Talha Zekeriya Durmuş wrote:

It processed 3000 request per second and that is almost near without file.write. So it is not about file writing thing. Slowness is relative with another thing.

It still could be files since the session doesn't just write one file.

For every new request it creates a new file with a different name and
slightly different content. It includes random values for CSRF checks,
so even if you don't save a session variable in your own code, it keeps
track of these random tokens and thus writes the file.

I'd love a better way to do this, but haven't found one yet. Maybe something
crypto based could avoid actually having to save the information.

Your benchmark would only do one file with the simple code, which Windows
might be caching in memory instead of committing it. With the web.d session
on that ab command, it would be writing 1,000 files....

@zek
Copy link
Author

zek commented Aug 28, 2013

And sorry I tested wrong server ip. Test results should not be taken notice of
.
Well I am using FASTCGI and web server will open 4-5 cgi application and each one will have different session datas? That couldn't. I don't know maybe you are making something for use each cgi application same session pool.

@adamdruppe
Copy link
Owner

i realize this is really old and so is the code I'm about to describe, but I might as well document it somewhere.

I created a better session system btw - compile with -version=webd_cookie_sessions. These will store all the session data in a signed client-side cookie. You'll also need hmac.d, the mhash C library (probably already installed on your system on Linux), and a file in the -J path called webd-cookie-signature-key.txt which should just be some long randomness.

Since it is on the client, it will all be visible to them, but since it is signed (if I did that right), it shouldn't be easy for them to modify.

It avoids files which is much faster than the old way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants