Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ Programming ➜ General ➜ Load testing script or program.

Load testing script or program.

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1 2  

Posted by Robert Powell   Australia  (367 posts)  Bio
Date Mon 10 Dec 2007 11:31 PM (UTC)
Message
Im looking for a program or script that is capable of logging in multiple characters and having them perform a series of command over and over, for testing out new code.

Currently i have been doing this in kmuddy with a bunch of triggers and macros, hardly eloquent but works well enough with up to 10 or 15 chars connected.

Idealy i was after a headless solution to this that would run in the background without any interface and have it load up 40 or more chars for testing.

Any ideas or tips on how to write such a beast would be appreciated.


Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #1 on Tue 11 Dec 2007 12:18 AM (UTC)
Message
If you don't mind using Lua, the LuaSocket library makes it particularly easy to talk to a server and send data to it. So you would write a script that took a character name and password, and then connected to the game, sending those in. Then it would just start sending whatever commands you want.

Of course, if you need trigger support and all that, you'll need to do something a little more complicated. There are terminal MUD clients out there, I just don't know of any offhand... anyhow, one of those might suit your purposes if you need more complicated than just sending data back and forth.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Robert Powell   Australia  (367 posts)  Bio
Date Reply #2 on Tue 11 Dec 2007 01:04 AM (UTC)
Message

f you don't mind using Lua, the LuaSocket library makes it particularly easy to talk to a server and send data to it. So you would write a script that took a character name and password, and then connected to the game, sending those in. Then it would just start sending whatever commands you want.


Actually that would be perfect, all i need is for it to establish and maintain a connection to the server and send a bunch of commands to the server that i supply it.

I dont know any Lua, but it might be time to learn some high level language like Lua that makes some things simple.

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #3 on Tue 11 Dec 2007 02:07 AM (UTC)
Message
Once you have Lua and LuaSocket installed, you would do something like this:


require 'socket'

local port = 1234
local conn = socket.connect("localhost", port)

conn:send("user\n")
conn:send("password\n")
conn:send("\n") -- if you have a MOTD you need to skip for instance

for i = 1, 1000 do
  conn:send("look\n")
  conn:send("north\n")
  conn:send("west\n")
  -- whatever
end


I think that's ridiculously easy... a lot easier than doing it in C at least. (Java is easier than C, but still...)

Most high-level languages are about this easy. Lua happens to be the one I know best...

If you're running a Linux-based system it will be very easy to install Lua. Under Debian-based systems, it would be something like:

sudo aptitude install lua5.1
sudo aptitude install liblua5.1-socket2


David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Robert Powell   Australia  (367 posts)  Bio
Date Reply #4 on Tue 11 Dec 2007 03:08 AM (UTC)
Message
I did a bit of reading about lua and came to the conclusion that writing a basic script to do what i want will be ridiculously easy, and thanks for demo as well.

I use Sabayon, a gentoo derivative, so ill emerge the lua packages i need later tonight when i have time to play with it.

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
Top

Posted by Robert Powell   Australia  (367 posts)  Bio
Date Reply #5 on Tue 11 Dec 2007 06:11 AM (UTC)
Message
Ok i get this error when i try and run that code,

lua: (command line):1: '=' expected near '<eof>'

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #6 on Tue 11 Dec 2007 06:45 AM (UTC)
Message
Hmm, how are you running it? If you try to run it line-by-line you might have trouble; I would put it into a single file and then run it like so:

lua foo.lua

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Robert Powell   Australia  (367 posts)  Bio
Date Reply #7 on Tue 11 Dec 2007 07:03 AM (UTC)
Message
If i run lua foo.lua it returns to the prompt and there is no connection made to the server.

But what i was doing was lua -e foo.lua which may not be the right thing to be doing i guess.

ok, so i guess the next question is why didnt i see any connection made to the server.

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #8 on Tue 11 Dec 2007 08:20 AM (UTC)
Message
Yeah... lua -e isn't what you want, as that is telling it to run the command "foo.lua" as a Lua string as opposed to reading the contents of the file foo.lua.

I'm also having trouble with the script as given; it appears to be writing too quickly and losing the connecting before the MUD gets a chance to say "hello". I'll look into it more tomorrow.

I guess it couldn't be that easy... :-P

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Robert Powell   Australia  (367 posts)  Bio
Date Reply #9 on Tue 11 Dec 2007 09:12 AM (UTC)
Message
In the mean time i will go and do some more reading on lua and see if i can learn something, Thanks for the help so far.

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
Top

Posted by Robert Powell   Australia  (367 posts)  Bio
Date Reply #10 on Thu 05 Jun 2008 05:13 AM (UTC)

Amended on Thu 05 Jun 2008 05:19 AM (UTC) by Robert Powell

Message
As nothing much became of this thread, i thought i would revive it to see if anyone made any head way with it or has a script in any language that can spawn a telnet session and send commands to the server.

I have been trying to do this in bash using expect, i can get the script to spawn the session and to enter the username, but it fails on password.


#!/usr/bin/expect 
   spawn telnet localhost 8000
   expect -re "user" 
   send "SomeUserName\r" 
   expect -re "Password" 
   send "SomePassWord\r" 


My idea was i could set up 50 or so scripts like this, start them all from a master script and have them output to nohup and leave them run in an infinite loop till i decide to kill them. Also they would run on the server itself so that i would not have the overhead of all that data traveling to and fro as i currently do running 20 players in mushclients.

Any thoughts and help would be great thanks.

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #11 on Thu 05 Jun 2008 05:26 AM (UTC)
Message
I am no expert on expect, but it looks to me like your script would sent to the terminal, not to the MUD server.

You probably should explore using luasocket, but it isn't totally trivial, especially in one script. It might be simpler if you just spawned one script per user, because then it could be "blocking".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Robert Powell   Australia  (367 posts)  Bio
Date Reply #12 on Thu 05 Jun 2008 05:54 AM (UTC)
Message
Isn't luasocket what we attempted earlier with David but could not get to work?

Im not sure what expect is doing, i can see from the output in the server that telnet connects, that the user is accepted, but it does nothing with the password. Im a a huge loss right now. LOL

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #13 on Thu 05 Jun 2008 07:02 AM (UTC)
Message
I think using luasocket is the way to go, it is pretty easy, considering the complexities of the underlying problem. I got David's example to work, with a bit of modification:


require 'socket'

local port = 4000
local host = "localhost"  -- or wherever it is
local conn = socket.connect (host, port)

assert (conn:send ("playername\n"))
socket.sleep (1)
assert (conn:send ("password\n"))
socket.sleep (1)
assert (conn:send ("\n\n\n")) -- if you have a MOTD you need to skip for instance
socket.sleep (1)

for i = 1, 10 do
  conn:send ("tell admin hi\n")
  conn:send ("look\n")
  conn:send ("north\n")
  conn:send ("west\n")
  socket.sleep (1)
  -- whatever
end


I threw in a few sleeps, partly because you would want to anyway (no player types that fast!) - and partly because it didn't work without them. According to the documentation for "send" the output is not buffered - effectively that means that if it can't be sent immediately, it is not sent at all.

Any sort of TCP/IP application needs to take into account that nothing is instantaneous. The connection defaults to blocking, I think, which is why you get away with sending the player name right after connecting, however remember that connecting, in itself, takes time.

If you can't get luasocket to work, read this thread:

http://www.gammon.com.au/forum/?id=8319

Once it is basically working, you should be able to run it outside MUSHclient. I did it from the command line, and basicallly to do that you do "lua <filename>" (eg. "lua stresstest.lua").

What programs like MUSHclient do (to send stuff) is something like this:


  • When you need to send, if stuff is outstanding, add it to the back of the queue

  • When the previous send completes (you use "select" to test for this) you take the first item from the queue, and do a "send".

  • The call to "send" tells you how much actually got sent (quite possibly less than you wanted), so you re-add the unsent part to the head of the queue.


I did a tiny client a while ago, see:

http://www.gammon.com.au/forum/?id=2206

That is quite a small C program that nonetheless shows the general technique. Its main loop (the processoutput function) basically loops around indefinitely, pausing on the "select" statement (there is select in the luasocket as well).

The select function is specifically designed to wait for "timeout" seconds, or until you can do something with your connection, whichever comes sooner. In this case, "doing something" could mean "ready to send more stuff". That is where you pull things out of your queue and send them, if required. The timeout can be used to gradually pump more stuff out, even if there is nothing outstanding.

A suitably designed script could set up dozens of connections, and then loop around checking if any of them are ready to do something (since select can check more than one socket at once).

I am reluctant to release a finished script that would do that, as it could be used by "script kiddies" to launch a denial-of-service attack on a MUD server with minimal effort.



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Robert Powell   Australia  (367 posts)  Bio
Date Reply #14 on Thu 05 Jun 2008 08:45 AM (UTC)
Message
I get this following error when i attempt to run the script,

lua: login.lua:7: attempt to index local 'conn' (a nil value)
stack traceback:
login.lua:7: in main chunk
[C]: ?
Any ideas?

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


55,210 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.