Jump to content

Reason of delay?


Recommended Posts

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. 

Link to comment
Share on other sites

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);
		}
	}

 

Link to comment
Share on other sites

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 ? 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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 Ο Χάρος
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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

    • Official Website @>> https://www.eventbrite.com/e/biopeak-male-enhancement-reviews-warning-important-information-no-one-will-tell-you-tickets-894184589177   Biopeak Male Enhancement:- Considering the mind-boggling interest in their products, the organization needed to confine the quantity of units ready to move. We considered what compelled this sugary treat to surprise the world, and we discussed whether it satisfied our grand assumptions,    https://www.facebook.com/BiopeakMaleEnhancementInUS/ https://www.facebook.com/Get.BiopeakMaleEnhancementUS/   https://trybiopeakme.clubeo.com/calendar/2024/04/29/biopeak-male-enhancement-reviews-the-disturbing-biopeak-supplements-truth https://trybiopeakme.clubeo.com/calendar/2024/04/28/biopeak-male-enhancement-reviews-warning-important-information-no-one-will-tell-you https://trybiopeakme.clubeo.com/calendar/2024/04/28/biopeak-male-enhancement-reviews-truth-exposed-2024-biopeak-supplements-usa-for-men https://medium.com/@BiopeakMaleEnhancementBuyNow/biopeak-male-enhancement-reviews-revitalize-your-sexual-biopeak-supplements-health-with-1b0dcc117608 https://medium.com/@BiopeakMaleEnhancementBuyNow/biopeak-male-enhancement-reviews-warning-usa-ca-important-information-no-one-will-tell-you-f375f53b3cd9 https://medium.com/@BiopeakMaleEnhancementBuyNow/biopeak-male-enhancement-reviews-truth-exposed-2024-is-biopeak-supplements-it-scam-or-real-9b8fc49be4c3 https://medium.com/@BiopeakMaleEnhancementBuyNow/be-informed-biopeak-male-enhancement-reviews-on-scam-alert-this-enhancement-for-male-female-2d49c8f9ec17   Nexalyn Norway Official Links   https://www.facebook.com/NexalynInNorway/ https://www.facebook.com/NexalynNorway/ https://nexalyn-norway.company.site/ https://nexalyn-norway.jimdosite.com/ https://nexalyn-norway-1.jimdosite.com/   https://infogram.com/nexalyn-norway-reviews-advarsel-viktig-informasjon-ingen-vil-fortelle-deg-1h0n25oyjvynz4p?live https://medium.com/@NexalynNorway/nexalyn-norway-reviews-truth-exposed-2024-nexalyn-tablet-iceland-for-men-ad3f06ce6c83 https://medium.com/@NexalynNorway/nexalyn-norway-reviews-2024-er-nexalyn-tablet-iceland-lovlig-eller-svindel-ac2a9a8506d3 https://medium.com/@NexalynNorway/nexalyn-norway-reviews-revitalisere-din-nexalyn-tablet-seksuelle-helse-med-a0d44852760c https://bonniedgrafh.clubeo.com/calendar/2024/04/26/nexalyn-norway-reviews-does-it-really-work https://bonniedgrafh.clubeo.com/calendar/2024/04/26/nexalyn-norway-reviews-revitalisere-din-nexalyn-tablet-seksuelle-helse-med https://bonniedgrafh.clubeo.com/calendar/2024/04/27/nexalyn-norway-reviews-advarsel-viktig-informasjon-ingen-vil-fortelle-deg https://bonniedgrafh.clubeo.com/calendar/2024/04/26/nexalyn-norway-reviews-testo-booster-pills-real-buyers-alert https://medium.com/@NexalynNorway/v%C3%A6r-informert-nexalyn-norway-reviews-om-svindelvarsel-denne-forbedringen-for-mannlig-og-kvinnelig-f52047570116
    • WELCOME TO THE BOXID MARKETPLACE THE BOXID is the best place to buy accounts in bulk. Also on THE BOXID there are any services for digital marketing and arbitrage! We offer cheap accounts and provide flexible prices, discounts and bonuses for loyal customers. If you want to make a bulk order, specify the quantity of items in the checkout form or contact our manager and ask for help with your bulk purchase. We sell social media at the most affordable price! https://theboxid.com/category/accounts/
    • Hello, I am adapting it to acis 401, and when I run it in the game it tells me: No rights defined for admin command 'admin_search'. Admin tried to use admin command 'admin_search', but has no access to use it.   Also try to adapt it in AdminAdmin.java with else in the last lines using it as admin_buscar (buscar = search in spanish) and I get the same error: No rights defined for admin command 'admin_buscar'. Admin tried to use admin command 'admin_search', but has no access to use it. I have the AdminSearch.java like this: package net.sf.l2j.gameserver.handler.admincommandhandlers; import java.util.Arrays; import java.util.List; import java.util.StringTokenizer; import net.sf.l2j.commons.lang.StringUtil; import net.sf.l2j.commons.math.MathUtil; import net.sf.l2j.gameserver.data.xml.ItemData; import net.sf.l2j.gameserver.handler.IAdminCommandHandler; import net.sf.l2j.gameserver.model.WorldObject; import net.sf.l2j.gameserver.model.actor.Player; import net.sf.l2j.gameserver.model.item.kind.Item; import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage; public class AdminSearch implements IAdminCommandHandler { private static final String[] ADMIN_COMMANDS = { "admin_search" }; private static final int PAGE_LIMIT = 15; @Override public void useAdminCommand(String command, Player activeChar) { if (command.startsWith("admin_search")) { StringTokenizer st = new StringTokenizer(command, " "); st.nextToken(); if (!st.hasMoreTokens()) { final NpcHtmlMessage html = new NpcHtmlMessage(0); html.setFile("data/html/admin/search.htm"); html.replace("%items%", ""); html.replace("%pages%", ""); activeChar.sendPacket(html); } else { final String item = st.nextToken(); int page = 1; if (st.hasMoreTokens()) { try { page = Integer.parseInt(st.nextToken()); } catch (NumberFormatException e) { page = 1; } } results(activeChar, item, page); } } return; } private static void results(Player activeChar, String item, int page) { final NpcHtmlMessage html = new NpcHtmlMessage(0); html.setFile("data/html/admin/search.htm"); //List<Item> items = new ArrayList<>();//no sirvio List<Object> items = Arrays.asList(ItemData.getInstance().getAllItems()); for (Object itemName : items) if (itemName != null) if (((WorldObject) itemName).getName().toLowerCase().contains(item.toLowerCase())) items.add(itemName); if (items.isEmpty()) { html.replace("%items%", "<tr><td>No items found with word " + item + ".</td></tr>"); html.replace("%pages%", ""); activeChar.sendPacket(html); return; } final int max = Math.min(100, MathUtil.countPagesNumber(items.size(), PAGE_LIMIT)); items = items.subList((page - 1) * PAGE_LIMIT, Math.min(page * PAGE_LIMIT, items.size())); final StringBuilder sb = new StringBuilder(); for (Object itemName : items) { String actualName = getFontedWord(item, ((WorldObject) itemName).getName()); StringUtil.append(sb, "<tr><td>", actualName, " (", ((Item) itemName).getItemId(), ")", "</td></tr>"); } html.replace("%items%", sb.toString()); sb.setLength(0); for (int i = 0; i < max; i++) { final int pagenr = i + 1; if (page == pagenr) StringUtil.append(sb, pagenr, "&nbsp;"); else StringUtil.append(sb, "<a action=\"bypass -h admin_search ", item, " ", pagenr, "\">", pagenr, "</a>&nbsp;"); } html.replace("%pages%", sb.toString()); activeChar.sendPacket(html); } private static String getFontedWord(String word, String tt) { int position = tt.toLowerCase().indexOf(word.toLowerCase()); StringBuilder str = new StringBuilder(tt); String font = "<FONT COLOR=\"LEVEL\">"; str.insert(position, font); str.insert(position + (font.length() + word.length()), "</FONT>"); return str.toString(); } @Override public String[] getAdminCommandList() { return ADMIN_COMMANDS; } } Can someone give me a hand and tell me what I'm doing wrong?  
    • Contact me: Disrcord : https://discord.gg/fJ5geYMu Skype: pparik2451 Email: golbergsoft@gmail.com You are welcome
    • Add Premium Account features. Add Weight Limit
  • Topics

×
×
  • Create New...