Too much sessions...

207 views
Skip to first unread message

Gaël Princivalle

unread,
Jul 12, 2019, 4:00:03 AM7/12/19
to web2py-users
Hi all.

In my sessions folder all sessions are stored in separated sub-folders, 068,069...
The file system don't accept more than 512 sub-folders in a folder.
When I reach 512 sub-folders the website is down.
Now for avoiding this problem I delete all the sessions with a crontab job every 12 hours, but it's not enough.

Obviously I can imagine that deleting all the sessions means also disconnecting all the users, that's not a good thing.

Can I store the sessions in the DB instead of the file system?

And what about that? I don't understand where I must add it, and it seems that the sessions storage for my website works already like that,

Thanks.


Fekete Zoltán

unread,
Jul 12, 2019, 4:46:44 AM7/12/19
to web2py-users
Hi Gael,

It is possible to store sessions in the db, however consider that it will slow down the system if you have such a high load.

A faster solution is to store sessions in memory:

Read that part of the doc, there are quite a few type of session handling recipes.

Regards,

FeZ

Gaël Princivalle

unread,
Jul 12, 2019, 9:37:08 AM7/12/19
to web2py-users
Thank you Zoltán.

I'm still trying this solution however when I create the 0_memcache.py model file I've got this ticket:

<type 'exceptions.ImportError'> Cannot import module 'applications.my_app.modules.six'


Could it be due to the fact that the web2py version is the old 2.14.6?

Fekete Zoltán

unread,
Jul 12, 2019, 10:04:24 AM7/12/19
to web2py-users
Could you please copy the whole error message?
Which python version do you use (2 or 3) ?

But in general, yes, I recommend to upgrade to the latest version for several reasons.

The module 'six' is a compatibility layer between API of python2 and python3 anyway.
I cannot see now why it should be in your apps module dir...

Regards,
FeZ

Gaël Princivalle

unread,
Jul 12, 2019, 10:22:46 AM7/12/19
to web2py-users
>Could you please copy the whole error message?

<type 'exceptions.ImportError'> Cannot import module 'applications.hydrover_oleodinamica.modules.six'

Versione

web2py™ Version 2.14.6-stable+timestamp.2016.05.10.00.21.47
Python Python 2.7.5: /usr/bin/python (prefix: /usr)

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
Traceback (most recent call last):
File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/restricted.py", line 227, in restricted
exec ccode in environment
File "/home/tasko/webapps/w2p_2_14_16/web2py/applications/hydrover_oleodinamica/models/0_memcache.py", line 2, in <module>
from gluon.contrib.memcache import MemcacheClient
File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/custom_import.py", line 108, in custom_importer
return NATIVE_IMPORTER(name, globals, locals, fromlist, level)
File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/contrib/memcache/__init__.py", line 1, in <module>
from gluon.contrib.memcache.memcache import Client
File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/custom_import.py", line 108, in custom_importer
return NATIVE_IMPORTER(name, globals, locals, fromlist, level)
File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/contrib/memcache/memcache.py", line 60, in <module>
import six
File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/custom_import.py", line 89, in custom_importer
raise ImportError, 'Cannot import module %s' % str(e)
ImportError: Cannot import module 'applications.hydrover_oleodinamica.modules.six'

Error snapshot help

<type 'exceptions.ImportError'>(Cannot import module 'applications.hydrover_oleodinamica.modules.six')

inspect attributes

Frames

  • File /home/tasko/webapps/w2p_2_14_16/web2py/gluon/restricted.py in restricted at line 227 code arguments variables

  • File /home/tasko/webapps/w2p_2_14_16/web2py/applications/hydrover_oleodinamica/models/0_memcache.py in <module> at line 2 code arguments variables

  • File /home/tasko/webapps/w2p_2_14_16/web2py/gluon/custom_import.py in custom_importer at line 108 code arguments variables

  • File /home/tasko/webapps/w2p_2_14_16/web2py/gluon/contrib/memcache/__init__.py in <module> at line 1 code arguments variables

  • File /home/tasko/webapps/w2p_2_14_16/web2py/gluon/custom_import.py in custom_importer at line 108 code arguments variables

  • File /home/tasko/webapps/w2p_2_14_16/web2py/gluon/contrib/memcache/memcache.py in <module> at line 60 code arguments variables

  • File /home/tasko/webapps/w2p_2_14_16/web2py/gluon/custom_import.py in custom_importer at line 89 code arguments variables

    Function argument list

    (name='six', globals={'__builtins__': {'ArithmeticError': <type 'exceptions.ArithmeticError'>, 'AssertionError': <type 'exceptions.AssertionError'>, 'AttributeError': <type 'exceptions.AttributeError'>, 'BaseException': <type 'exceptions.BaseException'>, 'BufferError': <type 'exceptions.BufferError'>, 'BytesWarning': <type 'exceptions.BytesWarning'>, 'DeprecationWarning': <type 'exceptions.DeprecationWarning'>, 'EOFError': <type 'exceptions.EOFError'>, 'Ellipsis': Ellipsis, 'EnvironmentError': <type 'exceptions.EnvironmentError'>, ...}, '__doc__': None, '__file__': None, '__name__': None, '__package__': None, 'binascii': None, 'os': None, 'pickle': None, 'print_function': None, 're': None, ...}, locals={'__builtins__': {'ArithmeticError': <type 'exceptions.ArithmeticError'>, 'AssertionError': <type 'exceptions.AssertionError'>, 'AttributeError': <type 'exceptions.AttributeError'>, 'BaseException': <type 'exceptions.BaseException'>, 'BufferError': <type 'exceptions.BufferError'>, 'BytesWarning': <type 'exceptions.BytesWarning'>, 'DeprecationWarning': <type 'exceptions.DeprecationWarning'>, 'EOFError': <type 'exceptions.EOFError'>, 'Ellipsis': Ellipsis, 'EnvironmentError': <type 'exceptions.EnvironmentError'>, ...}, '__doc__': None, '__file__': None, '__name__': None, '__package__': None, 'binascii': None, 'os': None, 'pickle': None, 'print_function': None, 're': None, ...}, fromlist=[], level=-1)

    Code listing
    84.
    85.
    86.
    87.
    88.
    89.

    90.
    91.
    92.
    93.
                            new_mod = base_importer(
    modules_prefix, globals, locals, [itemname], level)
    try:
    result = result or sys.modules[modules_prefix+'.'+itemname]
    except KeyError, e:
    raise ImportError, 'Cannot import module %s' % str(e)

    modules_prefix += "." + itemname
    return result
    else:
    # import like "from x import a, b, ..."
    Variables
    builtinstr <type 'str'>
    builtinImportError <type 'exceptions.ImportError'>
    e KeyError('applications.hydrover_oleodinamica.modules.six',)

In file: /home/tasko/webapps/w2p_2_14_16/web2py/applications/hydrover_oleodinamica/models/0_memcache.py

1.
2.
3.
4.
5.
6.
# -*- coding: utf-8 -*-
from gluon.contrib.memcache import MemcacheClient
memcache_servers = ['127.0.0.1:11211']
cache.memcache = MemcacheClient(request, memcache_servers)
cache.ram = cache.disk = cache.memcache

>Which python version do you use (2 or 3) ?
2

>But in general, yes, I recommend to upgrade to the latest version for several reasons.
I'm still planing to move to a 2.18.5, I've already installed it but in the welcome/modules folder there's only the __init__.py file, it's an empty file.

>The module 'six' is a compatibility layer between API of python2 and python3 anyway.
That could be the problem.

>I cannot see now why it should be in your apps module dir...
I've got __init__.py and pyc, api_site.pyc, plugin_ckeditor.py and pyc.

Fekete Zoltán

unread,
Jul 12, 2019, 10:48:22 AM7/12/19
to web2py-users
Try to install python-six module, restart the webserver or you web2py instance (whichever you have) and possibly you'll be OK.

Regards,

FeZ

Dave S

unread,
Jul 12, 2019, 6:09:22 PM7/12/19
to web2py-users


On Friday, July 12, 2019 at 1:00:03 AM UTC-7, Gaël Princivalle wrote:
Hi all.

In my sessions folder all sessions are stored in separated sub-folders, 068,069...
The file system don't accept more than 512 sub-folders in a folder.
When I reach 512 sub-folders the website is down.
Now for avoiding this problem I delete all the sessions with a crontab job every 12 hours, but it's not enough.

Obviously I can imagine that deleting all the sessions means also disconnecting all the users, that's not a good thing.

You've already moved on, it seems, but there's a script in the archives (I think I reposted it once, originally from Massimo)
and that script cleans up the sessions; with normal options, it deletes expired sessions only, but can delete all sessions older than x seconds, etc.

My website is getting around 5 hits per second 24-7; cleaning once a day was getting dicey (in df terms, rather than directly in dir entries), so I do it twice a day now -- via scheduler -- and manually if I look in and see an issue developing.
The script runs well as module called from the scheduler, and it sends me email if after cleaning df is still too low.
(This is an AWS ec2 instance, so the primary disk is small; we have a second disk we archive off to;
one app has a handful of uploads each week, and the uwsgi logs autorotate, but don't purge, so I still get to do housekeeping.)

/dps


Massimo Di Pierro

unread,
Jul 13, 2019, 3:03:17 AM7/13/19
to web2py-users
what os is this?

Fekete Zoltán

unread,
Jul 18, 2019, 5:03:37 AM7/18/19
to web2py-users
Hi Gael!

Could you solve the problem? Pls. give a short feedback.

Regards,
Zoltán

Gaël Princivalle

unread,
Jul 18, 2019, 6:56:36 AM7/18/19
to web2py-users
CentOS 7 on Webfaction.

Gaël Princivalle

unread,
Jul 18, 2019, 6:58:50 AM7/18/19
to web2py-users
Hi Zoltán, for the moment I've modified my crontab for deleting the sessions every hour.

I'll try to install python-six module and store the sessions in the memory in the next days.

Gaël Princivalle

unread,
Jul 19, 2019, 8:31:38 AM7/19/19
to web2py-users
Hi Zoltán.

python-six module is installed.

0_memcache.py is like in the documentation:
from gluon.contrib.memcache import MemcacheClient
memcache_servers = ['127.0.0.1:11211']
cache.memcache = MemcacheClient(request, memcache_servers)
cache.ram = cache.disk = cache.memcache

I've added this in the model db.py:
from gluon.contrib.memdb import MEMDB
session.connect(request, response, db=MEMDB(cache.memcache))

The last row generate this ticket:

Ticket ID

2a00_23a8_400d_c001_3d4c_5b50_35a9_dfdf.2019-07-19.12-25-46.c3413f14-b228-4390-bc14-2f7092907e01

Versione

web2py™Version 2.14.6-stable+timestamp.2016.05.10.00.21.47
PythonPython 2.7.5: /usr/bin/python (prefix: /usr)

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
Traceback (most recent call last):
File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/main.py", line 464, in wsgibase
session._try_store_in_db(request, response)
File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/globals.py", line 1183, in _try_store_in_db
record_id = table.insert(**dd)
File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/contrib/memdb.py", line 264, in insert
raise RuntimeError("Too many ID conflicts")
RuntimeError: Too many ID conflicts

Error snapshot help

<type 'exceptions.RuntimeError'>(Too many ID conflicts)

inspect attributes

Frames

  • File /home/tasko/webapps/w2p_2_14_16/web2py/gluon/main.py in wsgibase at line 464 code arguments variables

  • File /home/tasko/webapps/w2p_2_14_16/web2py/gluon/globals.py in _try_store_in_db at line 1183 code arguments variables

  • File /home/tasko/webapps/w2p_2_14_16/web2py/gluon/contrib/memdb.py in insert at line 264 code arguments variables

    Function argument list

    (self=<DALStorage {'client_ip': <pydal.objects.Field o... <pydal.objects.Field object at 0x7f6dd7c6e890>}>, **fields={'client_ip': '2a00.23a8.400d.c001.3d4c.5b50.35a9.dfdf', 'locked': False, 'modified_datetime': datetime.datetime(2019, 7, 19, 12, 25, 46, 854949), 'session_data': '\x80\x02cgluon.globals\nSession\nq\x01}q\x02(U\x19_formkey[no_tab...\x13(h\x0bU\r75.0.3770.142q\x14h\rU\x06Chromeq\x15u\x85Rq\x16u\x85Rq\x17u\x85Rq\x18.', 'unique_key': '25d6cb33-4709-4b14-987d-06aef044ac67'})

    Code listing
    259.
    260.
    261.
    262.
    263.
    264.

    265.
    266.
    267.
    268.
            for i in range(3):
    id = self._create_id()
    if self.get(id) is None and self.update(id, **fields):
    return long(id)
    else:
    raise RuntimeError("Too many ID conflicts")


    def get(self, id):
    val = self._tableobj.get(self._id_to_key(id))
    if val:
Do you know why?

Gaël Princivalle

unread,
Jul 29, 2019, 10:00:29 AM7/29/19
to web2py-users
Hi all.

I've got several problems for moving the sessions to the memory.
Now they're in the DB, adding this to the model:
session.connect(request, response, db)

It works fine and the website is faster.
Reply all
Reply to author
Forward
0 new messages