Welcome Guest, Not a member yet? Register   Sign In
Handling large traffic
#1

[eluser]faceh[/eluser]
One of my sites is lucky enough to be receiving thousands and thousands of hits and orders a day, which is great! and generally Codeigniter is handling it all really well.

However looking at the server logs of slow mysql queries, adding to and cleaning the sessions table seems to be struggling a little. I changed this table to InnoDB hoping the single row locking would help, however this caused multiple issues with: "Deadlock found when trying to get lock; try restarting transaction" - which was a fatal error causing issues, so I've reverted back to MyISAM for now.

Does anyone have some tips on handling sessions with very high traffic levels?

Thanks.
#2

[eluser]n0xie[/eluser]
Maybe change the session class to use Key/Value pair storage in memory instead of the database?
#3

[eluser]rogierb[/eluser]
You can convert the sessions table to a memory table (formerly knows as heap)

This is a lot faster then disk tables.
There are 2 things to consider:
Memory taken by the table, here has to be enought free memory for growth
And secondly that the table will be empty after mysql restart.

See http://dev.mysql.com/doc/refman/5.1/en/m...ngine.html for more info
#4

[eluser]faceh[/eluser]
rogierb, thank you for that. Memory was one thing i was considering, will get it set up in a test environment.

n0xie, sorry i'm not entirely sure what you mean. The site in question uses the database to store large amounts of userdata which must remain available for the session duration (2 hours) - would this still be possible?

In fact, in writing that "stores large amounts of userdata", I wonder if that is where the bottleneck lies, writing serialized data in to a long text field?
#5

[eluser]n0xie[/eluser]
Basically I'm saying the same as rogierb, but for the future you might want to take a look at memcached
#6

[eluser]faceh[/eluser]
I see, I will investigate MEMORY database storage then.

I actually have memcached and use it in other places, however for sessions where the data inside, even the last activity timestamp, is updated and changes quite regularly, and on top of that the result is unique for every user. I thought it probably wouldn't fit the memcached model as you'd have a memcache record for every sessions record.
#7

[eluser]Dirk Einecke[/eluser]
Hi,

[quote author="rogierb" date="1262807687"]You can convert the sessions table to a memory table (formerly knows as heap)[/quote]

But there is a problem: The type of the "user_data" column of the sessions table of codeigniter is a "TEXT" ... and a table with the StorageEngine MEMORY doesn't support TEXT fields.

Dirk
#8

[eluser]ChiefChirpa[/eluser]
[quote author="Dirk Einecke" date="1266177601"]Hi,

[quote author="rogierb" date="1262807687"]You can convert the sessions table to a memory table (formerly knows as heap)[/quote]

But there is a problem: The type of the "user_data" column of the sessions table of codeigniter is a "TEXT" ... and a table with the StorageEngine MEMORY doesn't support TEXT fields.

Dirk[/quote]

Which can easily be solved by changing the TEXT column to VARCHAR.
#9

[eluser]Dirk Einecke[/eluser]
Hi,

Quote:Which can easily be solved by changing the TEXT column to VARCHAR.

But if you've many data in the session a VARCHAR field is to small. You have to check the length of the fields content before you change it from TEXT to VARCHAR.

Dirk
#10

[eluser]ChiefChirpa[/eluser]
Quote:But if you’ve many data in the session a VARCHAR field is to small. You have to check the length of the fields content before you change it from TEXT to VARCHAR.

Which is only really a problem if:

1 - You use an old version of MySQL.
2 - You have some requirement to store far more than normal in the session.

For MySQL 5+ the size of VARCHAR is only limited by the maximum row size, which in theory lets you store up to 65,535 bytes, I'd suggest most people's session requirements fit into that very easily.




Theme © iAndrew 2016 - Forum software by © MyBB