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.
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

    • Hello everyone,    As you can see lately, the L2 community is decreasing, especially on private servers, its been 21 years since Lineage2 release date (1st October 2003). MaxCheaters.com was created in 2005 (with different names) and till today we are basically focused on Lineage 2. We made several attempts to add other games, but everyone still knew us as an L2 based forum. MaxCheaters has a long history and is one of the few forums that have survived to this day,It would be a shame to let the site die.   So I came up with a few ideas to improve it and follow the trends.   1. Create a utility token, (evm or solana), that will be used for several things such as: Staffers/moderators payment. Content creators reward system. (influencers/advertising/topic creators) Paid forum support. Exchanges and marketplaces . Lineage 2 utility token for private servers. Other MMO utility token for buying/selling accounts/gold etc. Maxcheaters fixed expenses/improvements/development/expansion/design/topsite   2. Reduce l2 sections, (we done this before) , and add more games on main page Less l2 sections More MMO games Focus on marketplaces    3. Rebuild staffers team/more events. Add one staffer per MMO game. More active staffers on our team.   4. Social media activity / streaming Twtter / TikTok content for gaming.  Streaming platforms (create official channel) Moderators/content creators for this content specifically.
    • From my personal experiences 🙂   Few months ago I decided to create my own Essence project. Project needs website, and I do not specialize in frontend development (t.y. i can make web work, but it won't be pretty for eye). So I search and find a guy in Discord, which claims he can make me a good looking HTML website for 30 EUR, prove some screenshots from his previous work. I agree. 1 week later, I get my HTML website, make few changes to contents, update URLs and upload it to FTP. Site looks good, I am happy that this headache is no more.   Few months passes. I randomly crawl through other Essence server websites scouting for good ideas for my own project. Suddenly one of russians project website opens and.. it's the same website as one I have 😉 perfectly absolutely same layout, colours, etc etc etc. I contact my guy to ask what the hell, to get blocked 😉  So I find a weekend worth of my time. Find HTML5 boilerplate generator and ask it to include Bootstrap 5 and some other stuff. Open Bootstrap documentation, drink two energy drinks on instant and start working my backend-inspired HTML black magic... Once I found suiting firefly effect for header, result looked oikay for me: Absolutely no magic or beauty here, but: * Unique (and probably nobody cares to rip it) * Done for free in ~10 hours by non-frontend dev * Most modern browsers friendly * Completely static content, loads instantly. No PHP at all * Sidebar statuses (online, pvp, pk) are pulled from account manager REST API endpoint and is cached for 5 minutes. Account manager runs separately from website frontend and has access to server DB. Where could/will it get better? * Code in Vue instead of HTML - time concerns only, but Vue is superior compared to HTML/PHP for supporting desktop/mobile, easing development by miles. Need to learn how to use it properly. * Way to manage content from backend - in my instance I think account manager is not really meant for that. Vue can help here too - there are components for content building. * Currently default Bootstrap components are used. Would be nice to have custom and more vibrant buttons. Guess what, Vue can help here too.   tl;dr don't buy 30EUR website, it will be ripped or shit. you better make your own website. Be curious. I am backend developer, I obviously have general idea how frontend works. But imho everyone who can make L2 server by editing NPC HTMLs, also can make their own simple website. ChatGPT and other AIs are your friends. Bootstrap. jQuery documentations are your friends. And when you feel good and comfortable with HTML, if you like, you can continue learning Vue, or going backend. Now, as for the top sites. You really need to invest money to make new project work. I mean really, really much money. For this concept to work, top website itself must get visited. But if you can sort that your top site would be popular amongst players, then it's a really very simple concept, as far as current 2004-ish sites goes. I think simple, working concept of this, maybe without proper frontend, but with implemented backend logics (add/edit/disable server, sort by votes count (top list), vote for server with verification, callback to server endpoint - all of that can be done using Symfony in mostly 5 days, with lots of breaks for coffee and a smoke 😉. Experienced mid frontend dev would make a Vue/React frontend for it in another 5 days. it's really really simple concept 🙂  
  • Topics

×
×
  • Create New...