Broker agent debugging

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Broker agent debugging

Porag
Hello everyone,

I am new to PowerTAC simulation and spring framework development. After going through the specification and other materials in the PowerTAC websites and wiki, I am able to run the server and the sample broker. Thanks for the well written documentation for getting started, it helped me a lot. Now I am trying to modify the sample broker so that I can make my own broker. So, I renamed the sample broker name in the broker.properties file and trying to do some development.

I am trying to understand the broker activities from the code level but having much difficulties. I tried to add some log codes like "log.info("Now in the function xxx....");" in the org.powertac.samplebroker package's PortfolioManagerService.java, ContextManagerService.java files in several handleMessages functions like CustomerBootstrapData, TariffStatus, TariffSpecification etc. Then I compiled the code and run using "mvn compile exec:exec". The problem is that I am unable to find the string "Now in the function...." in any of the broker logs i.e. state log and trace log. Then I deleted all the logs, did mvn clean and mvn compile exec:exec, but still can't find the debug string in the logs. There are 4 files, i.e. broker.trace & broker.state have nothing in it and broker1.trace & broker1.state. The string should be in the broker1.trace log, right? Am I making any mistakes in compiling and running the updated code?  

Is it possible to debug the broker code from STS like normal plain java program? (I feel no, because the broker needs to communicate with the server timely where 5 sec = 1 time slot in the server and the server is never halted by broker debugging, right?). If so, then what is the standard way to do debugging? I am eagerly waiting for any suggestions.

Thanks in advance
Porag
Reply | Threaded
Open this post in threaded view
|

Re: Broker agent debugging

grampajohn
Administrator
Hello, Porag -

Porag wrote
...

I am trying to understand the broker activities from the code level but having much difficulties. I tried to add some log codes like "log.info("Now in the function xxx....");" in the org.powertac.samplebroker package's PortfolioManagerService.java, ContextManagerService.java files in several handleMessages functions like CustomerBootstrapData, TariffStatus, TariffSpecification etc. Then I compiled the code and run using "mvn compile exec:exec". The problem is that I am unable to find the string "Now in the function...." in any of the broker logs i.e. state log and trace log. Then I deleted all the logs, did mvn clean and mvn compile exec:exec, but still can't find the debug string in the logs. There are 4 files, i.e. broker.trace & broker.state have nothing in it and broker1.trace & broker1.state. The string should be in the broker1.trace log, right? Am I making any mistakes in compiling and running the updated code?  
You are correct that the output from your log messages should show up in broker1.trace unless you run the broker in multi-session mode. There are a number of "log.info()" statements in the existing service implementations of SampleBroker. Are you seeing the log messages from those? If so, how do yours differ?

If you are not seeing output from the existing log statements, like the one in MarketManagerService.handleEvent(DistributionTransaction), then your broker is probably crashing or getting wedged somewhere. If that's the case, you could start by looking at the last few messages in the trace log and figure out where it's getting stuck. You could send me a URL where I could read one of your logfiles if you cannot see where it's stopping.

You can control the logging behavior to some extent by modifying src/main/resources/log4j.properties. See the log4j documentation for instructions on how to do this.
Is it possible to debug the broker code from STS like normal plain java program? (I feel no, because the broker needs to communicate with the server timely where 5 sec = 1 time slot in the server and the server is never halted by broker debugging, right?). If so, then what is the standard way to do debugging? I am eagerly waiting for any suggestions.
It's possible, yes. Depending on what you are trying to do, it may be easier to write unit-test cases - the debugger works really well with junit.

If it's too hard to write a test case, then there are two approaches that work: (1) add log outputs and see what's happening, and (2) pause the server before hitting a breakpoint. The broker can make this happen by sending a PauseRequest to stop the server and PauseRelease to re-start it. To enable this feature, you have to set server.competitionControlService.brokerPauseAllowed=true in the server config file. You can set this in server-distribution/config/server.properties, or in your own properties file that you specify with a command-line arg. Just that one line in a config file should be enough.

Perhaps David or some of the other broker developers could chime in with their favorite broker-debugging techniques.

Cheers -

John

Reply | Threaded
Open this post in threaded view
|

Re: Broker agent debugging

Porag
Sorry for late reply. Thank you very much for your response. I was able to fix the problem which was a really silly one.

I have some questions:

Q1. Sometimes I get error like this :

1092608 WARN  core.PowerTacBroker: worker thread waited more than 120 secs for server, abandoning game

Could please tell me for what reason this happens?

Q2. Sometime a market transaction have no clearing price! Is that normal?

Thanks
Porag
Reply | Threaded
Open this post in threaded view
|

Re: Broker agent debugging

grampajohn
Administrator
Porag wrote
Q1. Sometimes I get error like this :

1092608 WARN  core.PowerTacBroker: worker thread waited more than 120 secs for server, abandoning game

Could please tell me for what reason this happens?
See samplebroker.core.PowerTacBroker line 576. This should be a configurable value. If you want to change it you are of course free to do so, but this is really a bug. That code was inserted a few years ago when brokers were getting connected to the wrong game in a tournament after a previous game crashed or was aborted. We would be very happy to have you enter an issue on github to get this fixed, or even contribute your own fix.

So the other answer is probably one of (1) your network connection has failed, (2) your server has stopped for some reason without sending the SimEnd message, or (3) you have put a breakpoint in the server and spent more than 2 minutes with the server stopped.
Q2. Sometime a market transaction have no clearing price! Is that normal?
It is if the clearing price is zero. This is unusual, but not prohibited or impossible. Perhaps your broker is issuing some bids or asks with zero prices? If not, it would take some log analysis to figure out what's going on.

Cheers -

John