Jump to content

Recommended Posts

Posted

The reason for this post is to report a problem that can seriously affect the performance of your servers. Some of you maybe have not noticed, ought not to have many people using the buffer at the same time, but in my case 1 week ago, I had two total freezes when the whole server (500-700 players) attempted use the bufer after an event ;D. But I found something, a person is enough to knock over a server, with many people. Looks this code in script both original rin4a's buffer and my version have a problem, but is easy to fix.

 

as you can see in these lines of code, is open a connection to the database but is never closed, every time a user attempted to remove a buff of his scheme, open a new connection that was never closed causing a total server freeze.

 

                          if event == "remove_buff" :
                                      event = eventParam1.split("_")
                                      scheme = event[0]
                                      skill = event[1]
                                      level = event[2]
                                      con=L2DatabaseFactory.getInstance().getConnection()
                                      rem=con.prepareStatement("DELETE FROM buffer_scheme_contents WHERE scheme_id=? AND skill_id=? AND skill_level=? LIMIT 1")
                                      rem.setString(1, scheme)
                                      rem.setString(2, skill)
                                      rem.setString(3, level)
                                      try : rem.executeUpdate()
                                      except : pass

 

to fix the problem only adds to what I show below  :). thats all!

 

                          if event == "remove_buff" :
                                      event = eventParam1.split("_")
                                      scheme = event[0]
                                      skill = event[1]
                                      level = event[2]
                                      con=L2DatabaseFactory.getInstance().getConnection()
                                      rem=con.prepareStatement("DELETE FROM buffer_scheme_contents WHERE scheme_id=? AND skill_id=? AND skill_level=? LIMIT 1")
                                      rem.setString(1, scheme)
                                      rem.setString(2, skill)
                                      rem.setString(3, level)
                                      try :
                                                   rem.executeUpdate()
                                                   rem.close()         # <------------ADD----------
                                                   con.close()         # <------------ADD----------
                                      except : pass

 

After this modification, the performance of my server increase substantially (not more freezing, less lagg).

 

PD: I would recommend that only allow certain people to use the buffer for servers with more than 100 users (Use the VIP Option, i used and everything is fine).

 

I added that lines but when server try to load the script i got errors :

 

Failed executing script: C:\server\GameServer\data\scripts\custom\555_NPCBUFFER\

__init__.py. See __init__.py.error.log for details.

 

and in log is :

 

Error on: C:\server\GameServer\data\scripts\custom\555_NPCBUFFER\__init__.py.error.log

Line: -1 - Column: -1

 

Traceback (innermost last):

  (no code object) at line 0

SyntaxError: ('invalid syntax', ('__init__.py', 763, 25, '                        rem.close()'))

 

how it work at you ?

Posted

Anyone know a way to pull the description of the buff for each buff then display it under the icon/button/text for the actual buff?

 

A lot of people have a hard time making schemes because they forget what each one does. I am trying to edit and implement this into the buffer.

Posted

Well this information isn't embedded in the server's core, so you would have to make a new column in the buffers_buff_list table, add the description, and make the script to fetch that information. But there is a down side. You won't be able to list more than lets say 12 buffs per page. There are more than 130 buffs added, of course if you haven't added your own ones. So the script will have 10+ pages, and as far as I know, there can be some weird malfunctions in the HTML file.

Posted

Yeah anything after 9 pages starts getting glitchey...Guess I'll have to do this another way.

Thanks for the quick response Rin4a, I've always loved your buffer.

 

PS: You are everywhere xD

Posted

To be honest, I never took a look at the code of this buffer, that Allen modified. I just went with it, because it seemed to be working quite well. But performance wise - it's a mess. It's like every single script, that is out there, merged into a single file, and I'm not quite happy with that. But anyway - let's get back to my original script. I took some time out from L2j, but meanwhile I was studying pythons advanced features and I understood where I went wrong, while making this buffer. It was a total crap, if we judge it by it's performance. Features were OK. So what do I have in my mind. In this summer, I will try to rewrite this buffer completely. There won't be any stand alone functions, that are being called elsewhere, because I will be using classes. For tech geeks that are out there (yeah, I'm one of them lol) - I will be fully utilizing python's advanced OOP features and I will use string formatting feature, that is really cool.

To give a brief example:

# We will define a dummy variable, only to show, how to output it
dummy_var = "dog"

But for this example, we will output dog in double quotes. How did we do that earlier? Well..

print "I have a \"" + dummy_var + "\" and it's name is Rex"

So we had to concatenate dummy_var in the string and to output quotes, we had to use double double quotes and escape them and that might and will create a mess, but there is an other option, that works the same way, but is much clearer:

print "I have a \"%s\" and it's name is Rex" % dummy_var

We still had to escape double quotes, but if we had a bunch of variables that we would want to concatenate in the string, this method would work much much better.

Don't know why I wrote this, but someone might use it in their script.

Cheers.

Posted

Thats right, and this is important too http://www.skymind.com/~ocrow/python_string/. i will use Method 5 for now in my scripts. Thanks for advice. By the way, I think this method and what you said, can greatly increase the concatenation speed of any code, but implementing it in this buffer, is almost the same :S, this code is based in data base queries for everything (and that's just i try to avoid lately), so the concatenation speed and performance will be bad anyway :).

Posted

Queries ain't that bad, if you handle them correctly. In my old buffer, I used queries all the time, without thinking about the performance, but I will avoid that in my next release. I will fetch all the data from the database, when script will be initialized (when server will be starting) and store them in global arrays. So that way, the data will be there, when I need it, and I won't have to call any queries. In other words, I will be utilizing server's RAM more efficiently. I haven't thought about scheme system, because there might be more than 10k entries in the database, so I guess that I will have to use queries, despite everything, or I could make a dictionary, that will hold player's ID as a key and an array of skill ID's will be passed along. In total, 10k wouldn't be that much of a deal, but we will see..

  • 1 month later...
Posted

Ok I had your buffer working fine but I updated the server to a newer revision and now I get an error.

 

On Gameserver and htm of npc I get this error:

 

C:\Users\Giovanni Amorim\Desktop\magg\gameserver\data\scripts\custom\555_NPCBUFF
ER\__init__.py
Traceback (innermost last):
 (no code object) at line 0
       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

       at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
       at java.lang.reflect.Constructor.newInstance(Unknown Source)
       at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
       at com.mysql.jdbc.Util.getInstance(Util.java:384)
       at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
       at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3562)
       at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3494)
       at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1960)
       at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114)
       at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2696)
       at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.ja
va:2105)
       at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:
2264)
       at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewPr
oxyPreparedStatement.java:76)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: com.mysql.jdbc.except
ions.jdbc4.MySQLSyntaxErrorException: Table 'l2j_magg.buffer_scheme_list' doesn'
t exist

       at org.python.core.Py.JavaError(Unknown Source)
       at org.python.core.PyObject._jthrow(Unknown Source)
       at org.python.core.PyObject._jcall(Unknown Source)
       at org.python.proxies.main$Quest$437.onAdvEvent(Unknown Source)
       at com.l2jserver.gameserver.model.quest.Quest.notifyEvent(Quest.java:405
)
       at com.l2jserver.gameserver.model.actor.instance.L2PcInstance.processQue
stEvent(L2PcInstance.java:1838)
       at com.l2jserver.gameserver.network.clientpackets.RequestBypassToServer.
runImpl(RequestBypassToServer.java:259)
       at com.l2jserver.gameserver.network.clientpackets.L2GameClientPacket.run
(L2GameClientPacket.java:93)
       at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
       at java.lang.Thread.run(Unknown Source)

 

 

 

 

EDIT: I FIXED THE PROBLEM< I FORGOT TO ADD THE TABLES ON THE DATABASE

 

 

 

 

 

 

Guest
This topic is now closed to further replies.

×
×
  • Create New...