Jump to content

Recommended Posts

Posted

This also have a method i didnt see: 

activeChar.sendMessage("You gave " + player.giveAvailableSkills(includedByFs, true) + " skills to " + player.getName());

But the giveAvailableSkills is just this:

public int giveAvailableSkills(final boolean includedByFs, final boolean includeAutoGet)
	{
		int unLearnable = 0;
		int skillCounter = 0;

		List<L2SkillLearn> skills = SkillTreesData.getInstance().getAvailableSkills(this, getClassId(), includedByFs, includeAutoGet);
		while (skills.size() > unLearnable)
		{
			for (final L2SkillLearn s : skills)
			{
				final L2Skill sk = SkillTable.getInstance().getInfo(s.getSkillId(), s.getSkillLevel());
				if (sk == null || sk.getId() == L2Skill.SKILL_DIVINE_INSPIRATION && !Config.AUTO_LEARN_DIVINE_INSPIRATION && !isGM())
				{
					unLearnable++;
					continue;
				}
				if (getSkillLevel(sk.getId()) == -1)
				{
					skillCounter++;
				}
				// fix when learning toggle skills
				if (sk.isToggle())
				{
					final L2Effect toggleEffect = getFirstEffect(sk.getId());
					if (toggleEffect != null)
					{
						// stop old toggle skill effect, and give new toggle
						// skill effect back
						toggleEffect.exit();
						sk.getEffects(this, this);
					}
				}
				addSkill(sk, true);
			}
			// Get new available skills, some skills depend of previous skills to be available.
			skills = SkillTreesData.getInstance().getAvailableSkills(this, getClassId(), includedByFs, includeAutoGet);
		}
		sendMessage("You have learned " + skillCounter + " new skills.");
		return skillCounter;
	}

 

No db relative or flooding with sendMessage or packet flood. 

Posted

Damn it, the     addSkill(sk, true); 

at the code i showed you have  SQL relative code pff

public L2Skill addSkill(final L2Skill newSkill, final boolean store)
	{
		// Add a skill to the L2PcInstance _skills and its Func objects to the
		// calculator set of the L2PcInstance
		final L2Skill oldSkill = super.addSkill(newSkill);
		// Add or update a L2PcInstance skill in the character_skills table of
		// the database
		if (store)
		{
			storeSkill(newSkill, oldSkill, -1);
		}
		return oldSkill;
	}

You were right... damn this fucking SQL. 

private void storeSkill(final L2Skill newSkill, final L2Skill oldSkill, final int newClassIndex)
	{
		int classIndex = _classIndex;
		if (newClassIndex > -1)
		{
			classIndex = newClassIndex;
		}
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement;
			if (oldSkill != null && newSkill != null)
			{
				statement = con.prepareStatement(UPDATE_CHARACTER_SKILL_LEVEL);
				statement.setInt(1, newSkill.getLevel());
				statement.setInt(2, oldSkill.getId());
				statement.setInt(3, getObjectId());
				statement.setInt(4, classIndex);
				statement.execute();
				statement.close();
			}
			else if (newSkill != null)
			{
				statement = con.prepareStatement(ADD_NEW_SKILL);
				statement.setInt(1, getObjectId());
				statement.setInt(2, newSkill.getId());
				statement.setInt(3, newSkill.getLevel());
				statement.setInt(4, classIndex);
				statement.execute();
				statement.close();
			}
			else
			{
				_log.warning("could not store new skill. its NULL");
			}
		}
		catch (final Exception e)
		{
			_log.log(Level.WARNING, "Error could not store char skills: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

 

Posted
Just now, .Elfocrash said:

Ofc there would be sql related stuff. There is no way simple datastructures would lock things like this.

This look is draining the shit out of the db pool. H5 is only faster because it is using HikariCP (and potentially better code) which allows a bigger amound of connections in the pool to be used.

I'm not the best in SQL, what u suggest?  Maybe instead of open 1 connection for each skill to add all in 1 map and open 1 con and do a for e.t.c ? wouldnt this be faster?

Else what ? 

Posted
Just now, .Elfocrash said:

Well realistically what you can do now is to batch the datain the prepared statement and execute the batch. This should use one connection.

Here is an example in case you don't know what im talking about: https://www.mkyong.com/jdbc/jdbc-preparedstatement-example-batch-update/

However all this should be asynchronous but no one bothers to optimize performance in sql because they dont know how.

I set the addSkill(skill, false); so it won't store each skill individual using DB

and bellow i add the skill onto a List  and at the end of the code i call this method that i added

private void storeSkills(List<L2Skill> newSkills, int newClassIndex)
	{
		if (newSkills.isEmpty())
		{
			return;
		}
		
		final int classIndex = (newClassIndex > -1) ? newClassIndex : _classIndex;
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement(ADD_NEW_SKILLS))
		{
			con.setAutoCommit(false);
			for (final L2Skill addSkill : newSkills)
			{
				
				ps.setInt(1, getObjectId());
				ps.setInt(2, addSkill.getId());
				ps.setInt(3, addSkill.getLevel());
				ps.setInt(4, classIndex);
				ps.addBatch();
			}
			ps.executeBatch();
			con.commit();
		}
		catch (SQLException e)
		{
			
		}
	}

Which simply open 1 DB c and store all together. But how faster the HikariCP is? Can i upgrade to it? im not sql fan.

Posted
Just now, .Elfocrash said:

What i would do is this:

Creatin a new method called addSkills which allows an array of skills to be handled. You will need old and new skill separation for update and add

Ok i did. Ill go check in game to see the thread how much time it get sleep until db stuff finish. Thanks for ur help i wouldnt search further if u didn't say the word "DB" .

I kinda liked procedures in SQL but the overal structure and coding i dont like it. 

Posted (edited)
28 minutes ago, .Elfocrash said:

What i would do is this:

Creatin a new method called addSkills which allows an array of skills to be handled. You will need old and new skill separation for update and add

So process so far. I did what i wrote. Created new Map, stored each new skill on it. Changed the addSkill from true to false so it wont store individualy

at the end of the class i added the storeSkills. The method simply store all L2Skills at once without open 1000 DB con. Still in game 1.5 sec delay like i never changed anything.

The method turns out to Finalize after 77 milliseconds. I refer to this method 

public int giveAvailableSkills(final boolean includedByFs, final boolean includeAutoGet)
	{
		long ms = System.currentTimeMillis();
		
		int unLearnable = 0;
		int skillCounter = 0;

		List<L2SkillLearn> skills = SkillTreesData.getInstance().getAvailableSkills(this, getClassId(), includedByFs, includeAutoGet);
		List<L2Skill> skillsForStore = new ArrayList<>();
		
		while (skills.size() > unLearnable)
		{
			for (final L2SkillLearn s : skills)
			{
				final L2Skill sk = SkillTable.getInstance().getInfo(s.getSkillId(), s.getSkillLevel());
				if (sk == null || sk.getId() == L2Skill.SKILL_DIVINE_INSPIRATION && !Config.AUTO_LEARN_DIVINE_INSPIRATION && !isGM())
				{
					unLearnable++;
					continue;
				}
				if (getSkillLevel(sk.getId()) == -1)
				{
					skillCounter++;
				}
				// fix when learning toggle skills
				if (sk.isToggle())
				{
					final L2Effect toggleEffect = getFirstEffect(sk.getId());
					if (toggleEffect != null)
					{
						// stop old toggle skill effect, and give new toggle
						// skill effect back
						toggleEffect.exit();
						sk.getEffects(this, this);
					}
				}
				addSkill(sk, false); //addSkill(sk, true);
				skillsForStore.add(sk);
			}
			skills = SkillTreesData.getInstance().getAvailableSkills(this, getClassId(), includedByFs, includeAutoGet);
		}
		
		storeSkills(skillsForStore, -1);
		
		if (Config.AUTO_LEARN_SKILLS && (skillCounter > 0))
		{
			sendMessage("You have learned " + skillCounter + " new skills.");
		}
		
		System.out.println(System.currentTimeMillis() - ms);
		return skillCounter;
	}

 

So either the SQL data in Freya is shit as u said or client relative... idk any suggestion or could we implement HikariCP ?B

But again if it was SQL slow, it would be captured on the system.out..  it would say 3500 millisecond or something no 35... cause in this berchmark the sql con is included.

So it might be client lag? But i tried rotate immidiately after i get the skill list and the L2 respond fine, it rotate perfectly just the char doesnt move and suddedly he move x10 fast to the spot 

i clicked.

Edited by Ο Χάρος
Posted
Just now, .Elfocrash said:

It is the shitty sql which is made worse by the shitty cp

Using another db pooler simply hide the real problem, and hide all possible problems. It's sometimes good to get shitty db pooler.

:P

Posted (edited)

It doesn't enhance the problem, it highlights it. Which is great, otherwise it would be hidden.

Btw addBatch correct use depends of numerous factors ; used jdcb, mysql version, db type (myISAM/etc) etc. Using addBatch, it's not even sure it correctly processes the batch, it can transform it to regular single query.

Edited by Tryskell

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Posts

    • @Mobius I only asked you one question! All your previous versions are sh*t and the last version is the best ? Because this is what you said.
    • Close that LOLserver. And change name to L2Wipe&Money.
    • Open Beta January 17th & 21:00 UTC +2 Launch Date January 24th & 21:00 UTC +2 Click Here to Explore Vanilla Gracia Final Low-Rate Server. Join our Discord Community     Following the success of our Vanilla project, we decided to launch it again as Last PlayINERA’s Server! Core Settings *Vanilla will have Strict Botting & Client Limitation Rules and Chronicle Progression from Gracia Final to Gracia Epilogue to H5 in Long term! XP: x4 SP: x4 Adena: x2 Drop: x2 Spoil: x3 Manor: x0.4 (60% reduction) - Festive sweeper enabled! Seal Stones: x2 Herbs: x1 Safe Enchant: +3 Maximum Enchant: Retail Enchant Rate: Dynamic General Settings Auto-loot Can be toggled Buffs Adventurer Guide buffs are free, retail level limit removed. Buff Slots: 20 (+ 4) Summon buffs will remain on re-summoning & on death while Noblesse blessing is applied! (Olympiad excluded) Pet buffs will be saved on relog but not during summon/unsummon. Event Buffer [NEW] Event Buffer is enabled and will spawn randomly between 18:00 ~ 23:00 in Giran for 10 minutes, it will apply Farm Only buffs that are cancelled in PvP, Siege / Epic PvP zones & while in a chaotic state! Duration: 1-hour! Territory Wars every two weeks on Saturday. Castle sieges every two weeks on Sunday Class Transfer 1st Class Transfer: Available for purchase with either Adena or iCoin 2nd Class Transfer: Available for purchase with either Adena or iCoin 3rd Class Transfer: Quest or iCoin (the 3rd class transfer will become available for purchase with iCoin as soon as someone has entered the Hall of Fame for completing the 3rd class transfer quest for the class in question) Hellbound Hellbound Lv. 0-6: ATOD x1 Hellbound Lv. 7-12: ATOD x2 Tiat & Ekimus will become available at Stage 12 Hellbound can only be leveled up by killing monsters. No quests or raids are needed To open Hellbound, a party must kill Baylor in the Crystal Caverns The following items are now tradable: Ancient Tome of the Demon  Hidden First Page  Hidden Second Page  Demon Contract Fragment INERA Hub Library Clan Recruitment System Options Services Milestone Rewards Earn rewards for reaching various daily/one-time goals Client Limit: 1 (+1 with Standard Premium) Shift + Click Information on Monsters SP are required to learn new skills Offline shops Lasts for 15 days Olympiad Olympiad period: 1st and 15th day of the month (14th & Last day of month is the last day) 3 Vs. 3 match disabled Class-based matches will be held over the weekends One registration per HWID (PC) Minimum participants: 9 Party Matching System Earn bonuses for finding a group via the Party Matching system Vote Reward System World Chat No limits for first day! Available from level 20 Raid Bosses Epic Raid Boss zones will turn into a PvP zone while the Epic Raid Boss is alive ( + means Random) Server will start with all grand raids dead. Normal Raids: 12h (+6 hours random). Subclass raids, respawn 12h (+6 hours random). Noblesse Barakiel 12h (+6 hours random, PvP zone). Anakim & Lilith are static 24 hours respawn. Queen Ant: 24 hours (+2 hours random). Core: 40 hours (+2 hours random). Orfen: 32 hours (+2 hours random). Antharas Respawn: 8 Days. Randomly spawns at 19:00 ~ 21:00 Boosted to level 83 on Hellbound stage 7. Valakas Respawn: 10 Days. Randomly spawns at 19:00 ~ 21:00 Baium Respawn: 5 Days. Randomly spawns at 21:00 ~ 23:00 Boosted to level 83 on Hellbound stage 7. Frintezza Respawn: 2 Days. Randomly spawns at 21:00 ~ 23:00 Instanced Zaken Zaken (Day): Monday, Wednesday, Friday at 6:30. Zaken (Day): 9 players, LvL 55-65, 1hr max. Zaken (Night): Wednesday at 6:30 Zaken (Night): 18-45 players, LvL 55-65, 6hr max. Tiat: Saturday at 6:30, 18-36 players, 2 hrs max. Boosted to level 85. Ekimus: 24h at 6:30, 18-27 players, 1hr max. Tully’s Workshop (Darion & Tully): 24h +-1h. Tower of Naia (Beleth): 5 days, 18 min. & 36 max.
  • Topics

×
×
  • Create New...